Terminating app due to uncaught exception
‘NSInvalidArgumentException’,reason: ‘-[UITabBarController
tableViewListado]: unrecognized selector sent to instance
而不是接收预期的对象(ViewController)我得到“UITabBarController”,我是否应该在使用TabBar和Nav控制器时以不同的方式获得呈现控制器?
没有TabBar / Nav,我使用了这个:
ViewController *parentView = (ViewController *)[self presentingViewController]; [parentView something];
编辑:
只是发现如果我这样做它有效,但不要认为这实际上是最好的方法:
ViewController *parentView = (ViewController *)[(UINavigationController *)[((UITabBarController *)[self presentingViewController] ) selectedViewController] topViewController] ; [parentView something];
解决方法
从Programming iOS 6,by Matt Neuburg开始:
On the iPad,when the presented view controller’s modalPresentationStyle is UIModalPresentationCurrentContext,a decision has to be made as to what view controller should be the presented view controller’s presentingViewController. This will determine what view will be replaced by the presented view controller’s view. This decision involves another UIViewController property,definesPresentationContext (a BOOL). Starting with the view controller to which presentViewController:animated:completion: was sent,we walk up the chain of parent view controllers,looking for one whose definesPresentationContext property is YES. If we find one,that’s the one; it will be the presentingViewController,and its view will be replaced by the presented view controller’s view. If we don’t find one,things work as if the presented view controller’s modalPresentationStyle had been UIModalPresentationFullScreen.
TL; DR1.在所需的presentsViewController上将definePresentationContext设置为true2.在所需的presentViewController上将modalPresentationStyle设置为UIModalPresentationCurrentContext