gpt4 book ai didi

iphone - 调用父 View Controller (通过导航 Controller )

转载 作者:可可西里 更新时间:2023-11-01 03:22:24 25 4
gpt4 key购买 nike

目前,我使用 pushViewController:animated: 添加了一个 viewcontroller,现在我想从那个新 View Controller 中调用我的“父” Controller 中的一个方法。我想我卡在了导航 Controller 上。

目前正在尝试这样做以查看它是否是我想要的 Controller :

if([self.superclass isKindOfClass:[MySuperController class]])
// and tried:
if([self.presentingViewController isKindOfClass:[MySuperController class]])

这两个都不起作用。

如何访问推送当前 Controller 的 Controller (其中的一种方法)?

最佳答案

就像Marsson提到的,你需要使用delegate...

这是一个示例:

在您的 subview Controller .h 文件中:

@protocol ChildViewControllerDelegate <NSObject>
- (void)parentMethodThatChildCanCall;
@end

@interface ChildViewController : UIViewController
{
}
@property (assign) id <ChildViewControllerDelegate> delegate;

在您的 subview Controller .m 文件中:

@implementation ChildViewController
@synthesize delegate;


// to call parent method:
// [self.delegate parentMethodThatChildCanCall];

在父 View Controller .h 文件中:

@interface parentViewController <ChildViewControllerDelegate>

在父 View Controller .m 文件中:

//after create instant of your ChildViewController
childViewController.delegate = self;

- (void) parentMethodThatChildCanCall
{
//do thing
}

关于iphone - 调用父 View Controller (通过导航 Controller ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8055052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com