2012-06-06 16 views
8

Acabo de agregar TabBarController + NavigationController. Anterior a esto, todo estaba bien, pero ahora cuando llamo presentingViewController de un modal, me sale este error:presentingViewController consiguiendo siempre UITabBarController

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

En lugar de recibir el objeto esperado (ViewController) Estoy consiguiendo "UITabBarController", debería obtener la presentación controlador de alguna manera diferente cuando se utilizan los controladores TabBar y Nav?

Sin la TabBar/Nav yo estaba usando esto:

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

[parentView something]; 

Editar:

acaba de encontrar que si hago esto funciona, pero no creo que esto es en realidad la mejor manera de hacerlo:

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

[parentView something]; 
+0

es necesario agregar un poco de código en el que están llamando presentViewController. – rishi

+0

Acaba de agregar más información – dimirc

+0

mira esto - http://stackoverflow.com/questions/8437908/self-presentingviewcontroller-returns-uitabbarcontroller-not-the-view-controller – rishi

Respuesta

3

copia de mi respuesta de this question

de 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. establecer definesPresentationContext true en la deseada presentingViewController
2. establecer modalPresentationStyle a UIModalPresentationCurrentContext en la deseada presentedViewController

Cuestiones relacionadas