1

我有一个 VC,它以模态方式呈现另一个 VC。这第二个 VC 推送到第三个 VC。第三个 VC 自行解散,需要在初始 VC 上调用一个方法。我似乎无法让这个工作。有什么建议吗?

 VC3 *aVC3 = [[self.navigationController.viewControllers objectAtIndex:0] parentViewController];
 aVC3 = self.name;
 [aVC3 addExercise];
 [self dismissView];
4

2 回答 2

1

用于. delegate_backward messsaging

请参阅simple-delegate-tutorial-for-ios-development。另请参阅协议和代表的基础知识

如果您需要与 navigationController 中的任何 viewController 进行通信,例如UINavigationControllerno 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
于 2012-10-30T05:15:32.573 回答
-1

这是另一种方法:

第 1 步:FirstViewControllerSecondViewController.h

@interface SecondaryViewController : UIViewController{
}
@property (nonatomic, strong) FirstViewController *viewControllerOne;

self第 2 步:在呈现SecondViewControllerin时将该属性设置为FirstViewController.m

@implementation SecondaryViewController

-(void)functionThatPresentsSecondViewController{
    SecondViewController *viewControllerTwo = [[SecondViewController alloc] init];
    [viewControllerTwo setViewControllerOne: self];
    [self presentViewController:viewControllerTwo animated:NO completion:nil];
}

第 3 步:您现在可以使用该属性调用FirstViewController函数。SecondViewControllerviewControllerTwo.viewControllerOne

于 2012-10-30T05:45:45.383 回答