我有一个带有xib的UIViewController,当我尝试在其上呈现一个storyboard视图时,它会崩溃.
我用它来呈现它
UIViewController * buddiesOrFacebook = [self.storyboard instantiateViewControllerWithIdentifier:@"BuddiesFBFriends"] ; [self presentViewController:buddiesOrFacebook animated:YES completion:nil];
解决方法
检查这些事情
>检查viewcontroller的标识符,如果它与storyboard中提到的相同
>确保您的好友或朋友书不是零.在该行上设置断点,在底部的调试区域上查看对象是否为nil.如果它是零则问题在于故事板连接
>如果您当前的viewcontroller未从storyboard启动,那么获取如下的storyboard对象:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController * buddiesOrFacebook = [storyboard instantiateViewControllerWithIdentifier:@"BuddiesFBFriends"] ; [self presentViewController:buddiesOrFacebook animated:YES completion:nil];
Swift更新:
let storyboard = UIStoryboard(name: "MainStoryboard",bundle: nil) var buddiesOrFacebook = storyboard.instantiateViewControllerWithIdentifier("BuddiesFBFriends") self.presentViewController(myViewController,animated: true,completion: nil)