我有一个没有按计划工作的委托(delegate),我有这样的设置。我想调用函数 NSLog(show);
我不太清楚为什么这不起作用,但可以与我的其他 View Controller 一起使用。我一定是遗漏了一些小细节。
AccountViewController.h
@protocol AccountViewControllerDelegate;
@interface AccountViewController : UIViewController{
}
@property (nonatomic, assign) id <AccountViewControllerDelegate> accountViewDelegate;
@end
@protocol AccountViewControllerDelegate <NSObject>
- (void)showLabel;
@end
AccountViewController.m
-(IBAction)saveid)sender {
[self showLabel];
}
- (void)showLabel {
if (self.accountViewDelegate) {
NSLog(@"showlabel");
[self.accountViewDelegate showLabel];
}
}
MapViewController.m
-(void)showLabel {
NSLog(@"SHOW");
}
您尚未显示将 MapViewController 分配为 AccountViewController 的委托(delegate)的位置。也许这就是你所缺少的
//(from somewhere in the MapViewController)
AccountViewController *accountVC = //however you instantiate it (segue, storyboard etc
accountVC.accountViewDelegate = self;
关于iOS:我不确定,但我的委托(delegate)没有按我的计划工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20569331/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |