Application tried to present a nil modal view controller on target "Current View Controller"

StackOverflow https://stackoverflow.com/questions/23669417

  •  23-07-2023
  •  | 
  •  

문제

I have a UIViewController with xib , when I try to present a storyboard view on it , it crashes.

I present it using this

 UIViewController * buddiesOrFacebook = [self.storyboard   instantiateViewControllerWithIdentifier:@"BuddiesFBFriends"] ;
 [self presentViewController:buddiesOrFacebook animated:YES completion:nil];
도움이 되었습니까?

해결책

Check these things

  1. Check the identifier of the viewcontroller, if it is the same that you mentioned in storyboardenter image description here

  2. Make sure that your buddiesOrFacebook is not nil. Set a breakpoint on that line and on the debug area at the bottom see whether the object is not nil. If it is nil then problem lies in the storyboard connection

  3. If your current viewcontroller is not launched from storyboard then get storyboard object like this :

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController * buddiesOrFacebook = [storyboard   instantiateViewControllerWithIdentifier:@"BuddiesFBFriends"] ;
    [self presentViewController:buddiesOrFacebook animated:YES completion:nil];
    

Swift Update:

let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
var buddiesOrFacebook = storyboard.instantiateViewControllerWithIdentifier("BuddiesFBFriends")
self.presentViewController(myViewController, animated: true, completion: nil)

다른 팁

The thing that works for Me is : enter image description here

You have to mark the box is Initial View Controller to make it work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top