presentViewController:imagePickerController is popping my navigationController? - iphone

I am using presentViewController:imagePickerController to display the UIImagePickerController. For some reason when I end up dismissing that controller my original navigation controller looses it's stack and my application is back at the root view controller.
I am logging self.navigationController.viewControllers and I can see that after I run the presentViewController:imagePickerController line my navigation controller looses all of its controllers except for the root controller.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.navigationBarHidden = YES;
self.imagePickerController = imagePickerController;
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self.navigationController:%#",self.navigationController.viewControllers);
}];
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}
/////Where my NC is set up
OFMainViewController *mainController = [[OFMainViewController alloc]init];
mainController.managedObjectContext = self.managedObjectContext;
navigationController = [[UINavigationController alloc]initWithRootViewController:mainController];
[self.window setRootViewController:navigationController];

Instead of using self.navigationController use self for both dismissing and calling the imagepickerviewcontroller.

You should present imagePickeController on self instead of self.navigationController.
[self presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self:%#",self.navigationController.viewControllers);
}];
And dissmiss it accordingly:
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self dismissViewControllerAnimated:YES completion:^{
}];
}

Related

IOS 7 + For force controller Orientation to Portrait

I have used below code for IO6 and below to force rotate:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[c.view setBackgroundColor:[UIColor redColor]];
[self.navigationController presentViewController:c animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
}
But it is not working correctly on IOS7, it rotate view controller but again set blank view on screen...
Can you help me to solve this issue in IOS 7...
Change this line:
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
To this:
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];

Show another ViewController

help me please. How can I show another view controller after dismissing the existing one? here is my code:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
ViewController *Vc = [[ViewController alloc]init];
[self presentModalViewController:Vc animated:YES];
}
My code doesn't work. Help me please. If i wrote NSLog after dismissingModalViewController, it shows me that NSLog, but ViewController won't show. thanks
[self dismissModalViewControllerAnimated:YES]; has been deprecated. Try doing:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:^{
ViewController *Vc = [[ViewController alloc]init];
[self presentViewController:Vc animated:YES completion:^{}];
}];
}
Simply check this
[self dismissModalViewControllerAnimated:NO];
Nextview *sec = [[Nextview alloc] initWithNibName:#"Nextview" bundle:nil];
[self presentModalViewController:sec animated:YES];
[sec release];
Hope this works.

Unable to present modal view controller in didFinishWithResult

Is it possible to present Modal view controller in didFinishWithResult?
I have an iPad application with 3 views Home,Start and Login. Start and Login modal views can be launched using start and login buttons in home view.
If clicked on login button, after successful login operation (didFinishWithResult) in login view I am able to dismiss the login view and but i am not able to launch the start view. But the control stays back on home view.
I am not getting any error for the above scenario.
Appdeligate.m :
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
HomeViewController * homeview=[[HomeViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeview];
self.rootViewController = navigationController;
[navigationController setNavigationBarHidden:YES];
self.rootViewController.view.frame = [[UIScreen mainScreen] applicationFrame];
[self.window addSubview:self.rootViewController.view];
[window makeKeyAndVisible];
Below is the method in the home view which Present the login modal view
Presenting Login Modal View
LoginViewController * vc1 = [LoginViewController loginViewControllerWithNavBar:YES];
vc1.boxLoginDelegate = self;
[self presentModalViewController:vc1 animated:YES];
Note : LoginVeiwController is Modal view controller which is presented
by HomeViewController. Is it right way to launch/present another modal
view controller (start controller) by dismissing LoginVeiwController
as below. Because whenever the LoginVeiwController dismissed the control stays back on HomeVeiwContrller rather than launching/presenting StartViewController:
Home View :
Below is the method in the home view which will dismisses the login view on successful login and tries to launch the start view.
- (void)loginViewController:(LoginViewController *)loginViewController didFinishWithResult:(LoginResult)result {
[self dismissModalViewControllerAnimated:YES];
startview = [[[startViewController alloc] init] autorelease];
[self.navigationController setNavigationBarHidden:YES];
[self presentModalViewController:startview animated:YES];
}
If I present the StartView directly on button click, it launches nicely, but not on didFinishWithResult
Try like this. I think it will be helpful to you.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
HomeViewController * homeview=[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeview];
[self.window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES:
you need to restructure this line in your code [self dismissModalViewControllerAnimated:YES]; the reason being when dismiss is called, you loose self context of the controller and hence the line [self presentModalViewController:startview animated:YES]; is not showing any controller further.
to quicktest just comment dismiss line and see for yourself.
use this line when your currentViewController DissMiss then try bellow code...
[self performSelector:#selector(PresentView) withObject:nil afterDelay:0.2];
-(void)PresentView
{
[self.navigationController presentModalViewController:startview animated:YES];
}
hope,this help you....
:)
I guess it's about the animation. While the previous controller is dismissing,
[self presentModalViewController:startview animated:YES];
is called.
You can verify my guess by setting the animation to NO. Or directly use my suggestion to see if it works.
If I am correct, you can set them back to YES.
Besides, instead of directly calling the
[self presentModalViewController:startview animated:YES];
You can try:
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:#selector(showController) userInfo:nil repeats:No];
- (void)showController {
[self presentModalViewController:startview animated:YES];
}
edit:
I finally found out how I solve this similar problem before:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[UIView animateWithDuration:0.5
animations:^{
[self dismissModalViewControllerAnimated:YES];
}
completion:^(BOOL finished) {
NSURL *path = [info objectForKey:#"UIImagePickerControllerMediaURL"];
VideoConfirmViewController *videoConfirmCon = [[VideoConfirmViewController alloc]initWithFileURL:path];
[self presentModalViewController:videoConfirmCon animated:YES];
}
];
}
If you don't need compatibility with very old iOS versions it is better to use
-(void)presentViewControllerAnimated:completion:
-(void)dismissViewControllerAnimated:completion:
instead of
-(void)presentModalViewController:animated:
-(void)dismissModalViewController:animated:
In this case
- (void)loginViewController:(LoginViewController *)loginViewController didFinishWithResult:(LoginResult)result
{
[self dismissViewControllerAnimated:YES completion: ^{
startview = [[[startViewController alloc] init] autorelease];
[self.navigationController setNavigationBarHidden:YES];
[self.presentingViewController presentViewControllerAnimated:YES completion:NULL];
}];
}

How can I push a new viewController into an existing view within another view controller?

Is it possible to push a new viewController into an existing view within another view controller?
Here is my setup to begin with:
You can see that I have a UITableView. When a cell is tapped, a new view controller is pushed using this code;
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
Unfortunately this looks like this though and sits on top of the bar at the top saying "Will Roberts"
Why is this happening as it's clearly outside of the view I set it to be pushed from...
Instead of "presentViewController", use
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController pushViewController:viewcontroller animated:YES];
[viewcontroller release];
or use modal view controller
[self presentModalViewController:viewcontroller animated:YES]
//Presenting new view controller with navigation controller will help you.
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
//Edited
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[self presentModalViewController:nav1 animated:YES];

Why is presentModalViewController not working?

I am presenting a modalcontroller in a view, after i dissmiss the view i want to present another modalView but the code is not working, i have a delegate method that is being called when i press a button on the first modal vieview in witch i have the code.
inside the parentView the method for the firstview delegat:
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
[self dismissModalViewControllerAnimated:YES];
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
[self dismissModalViewControllerAnimated:YES];
}
You are presenting SecondView, which is your class and not your instance. Even if that was right, you are dismissing it straight away.
Move [self dismissModalViewControllerAnimated:YES]; to detailView.m
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
}
For example, in detailView.m
- (void)cancelBtnTouched:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}