iOS - Show UIPopoverController with TableView from Navigation Toolbarbutton - objective-c

I would like to display a UIPopoverController in my iPad app when the user taps a button which is at the lower toolbar provided by my NavigationController. Is there a tutorial on how I can do this? All I found was ancient tutorials from 2010.
Thank you in advance.

-(IBAction)ButtunClickMethod:(id)sender{
//create the table view controller from nib
self.tblLisView = [[[tableListVC alloc]
initWithNibName:#"tableListVC"
bundle:[NSBundle mainBundle]] autorelease];
//set popover content size
tblLisView.contentSizeForViewInPopover = CGSizeMake(170, 170);
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:tblLisView] autorelease];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
}

Related

Why does my Navigation Bar temporarily disappear when I dismiss a modal view in iOS 7?

When I'm going back from my Modal View Controller to my Main View Controller (I have a horizontal animation) my Main Controllers navbar places itself a bit too high for a quick second and then jumps back to its right position. Does somebody know why? Ive been googling it but with no success.
App Delegate:
[navigationController.navigationBar setBarTintColor: [UIColor whiteColor]];
[navigationController.navigationBar setTranslucent: NO];
When i push button to open my Info View:
UIViewController *infoViewController;
infoViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle: nil];
infoViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController: infoViewController animated: YES completion:nil];
I'm not using Auto Layout on any xib-files. My Main View Controller xib-file is empty with Status Bar: Default. My Info View Controller xib-file has some stuff in it.
Code for closing my Modal View Controller:
-(IBAction)onBackBtnClick:(id)sender
{
[self dismissModalViewControllerAnimated: YES];
}
All what you have to do is to add the following code in the ViewWillAppear of the "InfoViewController" viewController class
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar.layer removeAllAnimations];
}
Hope it worked with you :)
The problem seems to be
infoViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
If you change this to
infoViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
then it will no longer jump. This worked for me. Good luck!

I have no Navigation Bar in a view called with an IBAction?

My main menu (a ViewController) is embedded in a NavigationController that I added in the storyboard in Xcode4.
I have a button in my menu, displaying a new view. To display it I use :
- (IBAction) display : (id) sender
{
if(!anotherView) anotherView = [[AnotherView alloc] initWithNibName:#"AnotherView" bundle:nil];
[self presentModalViewController:anotherView animated:NO];
}
My other view is correctly displayed with all its objects and elements. Excluding my NavigationController's bar, that doesn't appear. Why ?
Thanks for your advices
You are presenting the view modally what you probably meant was
[self.navigationController pushViewController:anotherView animated:YES]
of course what you really want to do is not mix and match storyboard and non storyboard flows unnecessarily like this and have the storyboard do this for you
you are presenting your viewController modally. If you want to use the navigation controller you have to push your view onto the navigation stack.
replace
[self presentModalViewController:anotherView animated:NO];
with
[self.navigationController pushViewController:anotherViewController animated:YES];
You can still present your view modally without losing the navigation bar. Try this code:
AnotherView *tempAnotherView = [[AnotherView alloc] initWithNibName:#"AnotherView" bundle:nil];
[self setAnotherView:tempAnotherView];
[tempAnotherView release];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.anotherView] autorelease];
[self.navigationController presentModalViewController:navController animated:YES];
Hope it helps! :)

How to remove status bar from Modal ViewController in iOS App

I am working on a Children's book app for iPad and my app opens up an Modal Window to be able to select Male or Female Narrator. I am unable to remove the status bar from the Modal Window. Pls. see attached screenshot (highlighted in yellow color). Also, how do I make the window look pretty or make is transparent as it doesn't look too appealing at the moment?
Here is the code logic to open the ModalViewController inside my Main Controller:
-(IBAction)appLinkGet{
[self loadSetupModalView];
}
-(void)loadSetupModalView{
NSLog(#"ChildrenBookViewController ==> loadSetupModalView::");
// Create a Navigation controller
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.setupViewController];
//RESIZE THE MODAL VIEW
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:navController animated:YES];
navController.view.superview.autoresizingMask =
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
navController.view.superview.frame = CGRectMake(
navController.view.superview.frame.origin.x,
navController.view.superview.frame.origin.y,
540.0f,
400.0f
);
//navController.view.superview.center = self.view.center;
[navController release];
}
Try using this method:
[navController setNavigationBarHidden:YES animated:NO];

Presenting modal view controller from popover

I have a view controller that is inside a popover, and I want to present a modal view controller from it. Here's my code:
EditDateViewController *dateViewController = [[EditDateViewController alloc] initWithNibName:#"EditDateViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:dateViewController];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navController animated:YES];
[dateViewController release];
[navController release];
The result is this:
alt text http://cl.ly/5300e4f8f5d440d3f850/content
For some reason, the navigation bar background is transparent (or black?) even though I did not configure it that way. I tried manually setting the tintColor property of the navigation bar in the viewDidLoad method of the modal view controller, but it had no effect.
Try this
dateViewController.modalInPopover=YES;
self.navigationController.modalInPopover=YES;

UIView transition and animation

I understand modal views cover the entire screen. But I really want a view that covers only half the screen just like the keyboard. So, please tell me why this doesn't work
MyController *controller = [[MyController alloc] initWithNibName:#"MyView" bundle:nil];
CGRect frame = CGRectMake(0,44,768,264);
[controller view].frame = frame;
contoller.delegate = self;
[[self view] addSubView:[controller view]];
[controller release];
I am trying to add a sub view to my current view and make it appear where the keyboard appears.
It throws a BAD ACCESS exception
In my code (above), I was using a custom UIViewController with it's own view [set to UIView on IB]. I couldn't get it to work by setting frame for the view controller's view.
So I added a custom UIView without a Nib file with all the controls (buttons, textfields) added on initWithFrame.
MyCustomView = [[MyCustomView] alloc] initWithFrame:frame delegate:self];
[self.view addSubView:MyCustomView];
Thanks for your comment, Jacob.