我有一个VC,它以模态方式呈现另一个VC。第二个VC推送到第三个VC。第三个VC解散自己,需要在初始VC上调用一个方法。我似乎无法让这个工作。有什么建议吗?
VC3 *aVC3 = [[self.navigationController.viewControllers objectAtIndex:0] parentViewController];
aVC3 = self.name;
[aVC3 addExercise];
[self dismissView];
答案 0 :(得分:1)
delegate
使用backward messsaging
。
参考simple-delegate-tutorial-for-ios-development。另请参阅the-basics-of-protocols-and-delegates
如果你有UINavigationController
,no need of delegate
可以与navigationController中的任何viewController进行通信,如:
ViewController *objViewController = (ViewController *)[self.navigationController.viewControllers objectAtIndex:0]; //need to which controller u would like to communicate
[objViewController yourMethodHere]; // your method here
答案 1 :(得分:-1)
这是另一种方法:
第1步:在FirstViewController
SecondViewController.h
媒体资源
@interface SecondaryViewController : UIViewController{
}
@property (nonatomic, strong) FirstViewController *viewControllerOne;
第2步:在self
SecondViewController
时,将该属性设置为FirstViewController.m
@implementation SecondaryViewController
-(void)functionThatPresentsSecondViewController{
SecondViewController *viewControllerTwo = [[SecondViewController alloc] init];
[viewControllerTwo setViewControllerOne: self];
[self presentViewController:viewControllerTwo animated:NO completion:nil];
}
第3步:您现在可以使用FirstViewController
属性从SecondViewController
调用viewControllerTwo.viewControllerOne
个函数。