Lou*_*ley 7 iphone objective-c ios
目前我添加一个viewcontroller使用pushViewController:animated:,现在从内部新的想要调用我的"父"控件中的方法.我想我陷入了导航控制器.
目前正在尝试这个,看看它是否是我想要的控制器:
if([self.superclass isKindOfClass:[MySuperController class]])
// and tried:
if([self.presentingViewController isKindOfClass:[MySuperController class]])
Run Code Online (Sandbox Code Playgroud)
这两个都没有奏效.
如何访问推送当前控制器的控制器(其中的方法)?
use*_*234 37
就像Marsson提到的那样,你需要使用委托......
这是一个示例:
在您的子视图控制器.h文件中:
@protocol ChildViewControllerDelegate <NSObject>
- (void)parentMethodThatChildCanCall;
@end
@interface ChildViewController : UIViewController
{
}
@property (assign) id <ChildViewControllerDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)
在您的子视图控制器.m文件中:
@implementation ChildViewController
@synthesize delegate;
// to call parent method:
// [self.delegate parentMethodThatChildCanCall];
Run Code Online (Sandbox Code Playgroud)
在父视图控制器.h文件中:
@interface parentViewController <ChildViewControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
在父视图控制器.m文件中:
//after create instant of your ChildViewController
childViewController.delegate = self;
- (void) parentMethodThatChildCanCall
{
//do thing
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15722 次 |
| 最近记录: |