Storyboard modal segue presenting inside popover - ios5

The last segue in one branch of the "master" side of my splitViewController is a modal (fullscreen) segue from a tableViewCell in the master to a tableViewController.
When the device is landscape everything works fine, the new tableViewController is presented in fullscreen as expected.
When the device is portrait, however, and the masterVC is displayed using the popover button, selecting the tableViewCell causes the modal segue to present the new TableVC inside the popover rather than in fullscreen.
After dismissing the Modal VC (from within the master popover) the layout of the popover is "off" i.e. the table is not autoresized properly for the popover.
Can anyone tell me why? or point me in the right direction to solving this...
Thanks.

By default the UIViewController being presented inherits the presentation context of the presenter.
You can change this by modifying the modalPresentationStyle and optionally the modalTransitionStyle of the UIViewController you want to present modally.
UIViewController* myModalVC = [UIViewController alloc] init];
myModalVC .modalPresentationStyle = UIModalPresentationFullScreen;
//myModalVC .modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:rViewController animated:YES completion:nil];

Related

Warning: Attempt to present <CustomViewController> on <UINavigationontroller> whose view is not in the window hierarchy

I know this has been asked a million times, but I couldn't find a suitable answer in those many questions that I've examined.
I have a custom view controller, and I'm trying to display the view controller when the user taps a button (so no "infamous viewDidLoad problem" here).
Here is my code that runs when the user taps the button: (I have the NIB for the view controller, and I have a navigation controller)
ICLoginViewController *loginViewController = [[ICLoginViewController alloc] initWithNibName:#"ICLoginViewController" bundle:[NSBundle mainBundle]];
//assuming we have a navigation controller.
UINavigationController *navigationController= (UINavigationController*)[[UIApplication sharedApplication] keyWindow].rootViewController;
[navigationController.topViewController presentViewController:loginViewController animated:YES completion:nil];
I'm getting the Warning: Attempt to present <ICLoginViewController: 0xa08a810> on <UINavigationController: 0xa45de70> whose view is not in the window hierarchy! error when I try to present the view controller. Nothing happens on screen. If I tap multiple times I get the same error, and still nothing happens. I've set a breakpoint and verified that navigationController and navigationController.topViewController are not nil. I' using storyboard (if it helps) but not for the custom view controller that I'm trying to display. (I want to make it an app-independent library in the long run, so I'm not referencing any app-specific modules within) Why am I getting this error?
I've found the solution. The problem was, my modally displayed view controller was not the 'top' view controller in navigation controller. If I change the calling view controller to be pushed instead of being modal, then it becomes the top view controller and my app works well. Apparently, this had nothing to do with my custom view controller, but my navigation stack.
If its in an NSObject create a method inside the NSObject that takes your current viewController as an argument and present it there.
eg:
-(void)presentInViewController:(UIViewController *)controller{
ICLoginViewController *loginViewController = [[ICLoginViewController alloc] initWithNibName:#"ICLoginViewController" bundle:[NSBundle mainBundle]];
[controller presentViewController:loginViewController animated:YES completion:^(BOOL comp){}];
}
This way you can call that view controller wherever you want instead of trying to find your way through the navigation stack from UIApplication.

Navigation bar not visible when manual segue

I have a little problem with segues in my app. I am trying to manual PUSH segue. But navigation item/controller/bar is not visible on target controller. When i use button and segue with that button to target view controller, navigation bar IS visible :/
My code is simple:
[self performSegueWithIdentifier:#"MySegue" sender:self];
MySegue is push segue from root view controller of UINavigationController to target controller.
It even did not work with this one
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:[NSBundle mainBundle]];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"TargetViewController"];
[self.navigationController pushViewController:controller animated:YES];
and even if i set top bar (navigation item) in story board manualy
thanks for any help:)
Delete the segue that goes from StaznostiViewController to StaznostViewController. Control-drag from the StaznostiViewController object (in the bar below the view) to the StaznostViewController, NOT from the StaznostiViewController view or from the StaznostiViewController tableview prototype cell. Select Push style. Name your segue whatever you wish.
In your code, in the target-action method that you have defined for your dynamic button(s), this is where you call the method performSegueWithIdentifier.
Also, make sure that in the properties for StaznostViewController, you have the property for Top Bar set to Inferred.
Same thing happened to me. I created a "Push" segue from storyboard, and was calling it from code. Then it lost navigation items on the navigation bar. When I changed the segue to "Modal", then navigation items of the destination view appeared properly. .
try nil sender instead of self:
[self performSegueWithIdentifier:#"MySegue" sender:nil];
hope it works

iPhone - change navigation controller's view, using a button in a subview

I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.
However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.
At the moment, it builds and runs, but the new view is not pushed. Any ideas?
Click method on on the ScrollItem button:
MyViewController *newView = [[MyViewController alloc] initWithNibName:#"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
... i guess it is because, self doesn't have a navigation controller, but the rootview does.
Thanks!!
The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.
Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.
So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

Pushing a UIViewController from a modal view controller

I am using a split view controller in an iPad app I am trying to make.
Right now, I have a view being displayed in a modal view controller using:
[self presentModalViewController:viewController animated:YES];
and that works fine, but when the user presses a button, I want the root view controller to push to another view. I am using:
RootViewController *rvc = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
[rcv pushViewController:rvc animated:YES];
but that is not working. What should I do?
--EDIT
Now, I am using
PhotosViewController *pv = [[PhotosViewController alloc] initWithNibName:#"PhotosViewController" bundle:nil];
[self.parentViewController.navigationController pushViewController:pv animated:YES];
NSLog(#"Navigation Controller: %#", self.parentViewController.naviagtionController);
When I do the NSLog call, it returns nil. Why is that?
Once again, I am using a split view controller and am trying to push the RootViewController to a new view.
Thanks
Your code isn't working because you're created a RootViewController instance and then trying to push it onto itself. What you should be doing is pushing the new view controller onto the parent view controller's navigation controller:
[self.parentViewController.navigationController pushViewController:newViewController animated:YES];
I know this is an old question but I believe the proper way "now" to push a viewController onto the main navigation stack from a modal viewController is to create a "didTapShowBlahViewController" delegate on the modal (this is assuming you want the user to be finished with the existing modal view and then push a new view onto the stack). Once you have that delegate, you simply have the view that initially invoked the modal to perform dismissing the modal and pushing the next view controller when the delegate is triggered.
- (void)didTapShowBlahViewController{
[self dismissViewControllerAnimated:YES completion: nil];
[self performSegueWithIdentifier:#"segueToBlahViewController" sender:self];
}
This is based on Apple's View Controller Programming Guide that specifies passing data to child view controllers and using delegates to pass data back to parents.
FYI: This way also ensures that the "back" button will not go back to the modal but instead to the view that invoked the modal, which is how modals are typically used.

tabBarController navigation problem/question

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}
A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.