菜鸟教程小白 发表于 2022-12-13 05:37:40

iOS:我不确定,但我的委托(delegate)没有按我的计划工作


                                            <p><p>我有一个没有按计划工作的委托(delegate),我有这样的设置。我想调用函数 <code>NSLog(show);</code> 我不太清楚为什么这不起作用,但可以与我的其他 ViewController 一起使用。我一定是遗漏了一些小细节。</p>

<p><strong>AccountViewController.h</strong></p>

<pre><code>@protocol AccountViewControllerDelegate;
@interface AccountViewController : UIViewController{

}
@property (nonatomic, assign) id &lt;AccountViewControllerDelegate&gt; accountViewDelegate;
@end

@protocol AccountViewControllerDelegate &lt;NSObject&gt;
- (void)showLabel;
@end
</code></pre>

<p><strong>AccountViewController.m</strong></p>

<pre><code>-(IBAction)save:(id)sender {
    ;
}

- (void)showLabel {
    if (self.accountViewDelegate) {
      NSLog(@&#34;showlabel&#34;);

      ;
    }
}
</code></pre>

<p><strong>MapViewController.m</strong></p>

<pre><code>-(void)showLabel {
    NSLog(@&#34;SHOW&#34;);
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您尚未显示将 MapViewController 分配为 AccountViewController 的委托(delegate)的位置。也许这就是你所缺少的</p>

<pre><code>//(from somewhere in the MapViewController)

AccountViewController *accountVC = //however you instantiate it (segue, storyboard etc
accountVC.accountViewDelegate = self;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iOS:我不确定,但我的委托(delegate)没有按我的计划工作,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/20569331/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/20569331/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS:我不确定,但我的委托(delegate)没有按我的计划工作