OGeek|极客世界-中国程序员成长平台

标题: iOS:我不确定,但我的委托(delegate)没有按我的计划工作 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:37
标题: iOS:我不确定,但我的委托(delegate)没有按我的计划工作

我有一个没有按计划工作的委托(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");
}



Best Answer-推荐答案


您尚未显示将 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4