简体   繁体   中英

Xcode Can't Call/Dismiss viewcontroller from PopUp

This is going to take some explaining... So I'll do it in order:

  1. I have a navigation controller where the rootViewController is called TipsCollectionViewController.
  2. I have a UserViewController that's loaded as a popup:

    UserViewController * userView = [[UserViewController alloc] initWithNibName:@"UserView" bundle:[NSBundle mainBundle]]; [userView setUEmail:email]; [self presentPopupViewController:userView animationType:MJPopupViewAnimationSlideTopBottom];

  3. I then have another popup that loads on top of THAT popup:

    Place *p = [placeArray objectAtIndex:indexPath.row];

     DetailPlaceViewController *pvc = [[DetailPlaceViewController alloc] init]; [pvc setPlace:p]; NSLog(@"%@", p.PName); [self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom]; 

Now there's a reason I've done this: the AppDelegate features a Navigation controller and previously I loaded the UserView like this:

[self.navigationController presentViewController:userView animated:YES completion:nil];

But this meant that the UserView would load on the iPhone but not on the iPad for some odd reason. But when I switched it to the popup view it worked fine.

So now I load both the UserView and the DetailPlaceView in a popup... but now it CLOSES on the iPad but not on the iPhone.

Here's the code for closing the detail view:

- (void) didTapBackButton:(id)sender {
    NSLog(@"View Controller Number: %lu", (unsigned long)self.navigationController.viewControllers.count);
    if(self.navigationController.viewControllers.count > 1) {
        [self.navigationController popViewControllerAnimated:YES];
        NSArray *stack = self.navigationController.viewControllers;
        TipCollectionViewController *tipsVC = stack[stack.count-1];
        [tipsVC.collectionView reloadData];
}

I know there's a better way to handle this whole thing... but what should I be doing differently?

UPDATE

If I switch it back to:

[self.navigationController pushViewController:userview animated:YES]; 

...for the UserView on the iPhone and:

[self.navigationController pushViewController:pvc animated:YES];

...for the view that loads after that, then the UserView will load... but the next viewcontroller (the DetailPlaceViewController) won't load. I think that's my main problem. I could probably dismiss the second view controller at that point if I could get it to load. Any ideas?

[self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom];

if you are using this,presentPopupViewController is used to display like modal view which cant be dismissed without any custom cancellation action.

To use popOverViewController method, use pushViewController. Then that one you can dismiss by this technique.

Ultimately all I had to do was switch:

[self.navigationController pushViewController:pvc animated:YES];

to:

[self presentViewController:pvc animated:YES];

And it works. It opens and closes the view and everything works as it should.

I'm getting a warning on the DetailView once you click an item:

Presenting view controllers on detached view controllers is discouraged <UserViewController: 0x16e02020>

So I'll wait a couple of days to accept my answer. Otherwise, despite the warning, it seems to be working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM