我是新的objective-c。我尝试在2个视图控制器(例如controllerA和controllerB)之间发送数据,但我不断需要这些数据,因此我使用controllerB中的_displaylink从controllerA调用方法。我在控制器A中使用播放器,我想在控制器B中显示时间等。如何获得controllerA的现有实例?不断在两个视图控制器之间传递数据iOS
我尝试两种不同的方式来做到这一点,但两者创建视图 - 控制
例1的新实例:
RootViewController *controller=(RootViewController *)self.presentedViewController;
例子2:
RootViewController *parent=self.parentViewController;
当我用这个解决方案我可以调用控制器A的方法(但是这是从新实例:()的方法:()
我也尝试此解决方案:
RootViewController *rootController =(RootViewController*)[[(AppDelegate*)
[[UIApplication sharedApplication]delegate] window] rootViewController];
但是当我尝试调用的方法在我得到这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MMDrawerController playerPositionS]: unrecognized selector sent to instance 0x7c406c00'
任何想法如何调用此方法是否正确?
两者都不创建viewcontroller的新实例。 ControllerB是ControllerA的childViewController吗?发布一些代码以查看控制器A + B之间的hirachie。 – shallowThought
使用协议/委托 – Rajat
ControllerB是在ControllerA – MaSza