2012-06-06 12 views
8

Ich füge nur TabBarController + NavigationController. Vor dieser alles war in Ordnung, aber wenn ich jetzt presentingViewController von einem modalen anrufe, bekomme ich diesen Fehler:presentingViewController bekomme immer UITabBarController

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController tableViewListado]: unrecognized selector sent to instance

Statt der erwarteten Objektaufnahme (Viewcontroller) Ich erhalte „UITabBarController“, sollte ich die präsentierenden bekommen Controller auf eine andere Art und Weise, wenn TabBar und Nav Controller verwendet werden?

Ohne die TabBar/Nav ich dies wurde mit:

ViewController *parentView = (ViewController *)[self presentingViewController]; 

[parentView something]; 

Edit:

nur herausfinden, dass, wenn ich dies tun, funktioniert es, aber glaube nicht, dass dies tatsächlich der beste Weg ist, es tun:

ViewController *parentView = (ViewController *)[(UINavigationController *)[((UITabBarController *)[self presentingViewController]) selectedViewController] topViewController] ; 

[parentView something]; 
+0

Sie Code hinzufügen müssen Sie wo rufen presentingViewController auf. – rishi

+0

Nur hinzugefügt mehr Info – dimirc

+0

check this out - http://stackoverflow.com/questions/8437908/self-presentingviewcontroller-returns-uitabbarcontroller-not-the-view-controller – rishi

Antwort

3

Kopie meiner Antwort von this question

von 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; DR
1 gesetzt definesPresentationContext auf true auf den gewünschten presentingViewController
2 gesetzt modalPresentationStyle-UIModalPresentationCurrentContext auf den gewünschten presentedViewController

Verwandte Themen