我有一个 VC,它以模态方式呈现另一个 VC。这第二个 VC 推送到第三个 VC。第三个 VC 自行解散,需要在初始 VC 上调用一个方法。我似乎无法让这个工作。有什么建议吗?
VC3 *aVC3 = [[self.navigationController.viewControllers objectAtIndex:0] parentViewController];
aVC3 = self.name;
[aVC3 addExercise];
[self dismissView];
我有一个 VC,它以模态方式呈现另一个 VC。这第二个 VC 推送到第三个 VC。第三个 VC 自行解散,需要在初始 VC 上调用一个方法。我似乎无法让这个工作。有什么建议吗?
VC3 *aVC3 = [[self.navigationController.viewControllers objectAtIndex:0] parentViewController];
aVC3 = self.name;
[aVC3 addExercise];
[self dismissView];
用于. delegate
_backward messsaging
请参阅simple-delegate-tutorial-for-ios-development。另请参阅协议和代表的基础知识
如果您需要与 navigationController 中的任何 viewController 进行通信,例如UINavigationController
:no need of delegate
ViewController *objViewController = (ViewController *)[self.navigationController.viewControllers objectAtIndex:0]; //need to which controller u would like to communicate
[objViewController yourMethodHere]; // your method here
这是另一种方法:
第 1 步:FirstViewController
在SecondViewController.h
@interface SecondaryViewController : UIViewController{
}
@property (nonatomic, strong) FirstViewController *viewControllerOne;
self
第 2 步:在呈现SecondViewController
in时将该属性设置为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