本文介绍了委托的自定义设置器方法被称为无限次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VC中,我声明了一个自定义委托属性:

In my VC I have declared a custom delegate property:

@interface VC2 : BaseVC
@property (nonatomic,weak) id<VC2Delegate> delegate;
@end

从VC1中,我正在设置此委托人:

and from VC1, I'm setting this delegate:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString: @"VC2"]) {
        self.VC2 = [segue destinationViewController];
        [self.VC2 setDelegate:self];
    }
  }

在我的VC2中,我编写了一个setter方法对于代表:

and in my VC2, I have written a setter method for the delegate:

-(void)setDelegate:(id)del{
    self.delegate=del;
}

在VC1中调用pprepareForSegue方法后,该问题是委托者的setter方法在VC2中被调用了很多次,我的应用程序崩溃了。我不确定这可能是什么原因。

The issue, after the pprepareForSegue method call in VC1, the setter method for delegate in VC2 gets called so many times and my apps get crashed. I'm not sure what could be the reason.

这是satcktrace:

Here is the satcktrace:

我的BaseVC没有任何实现。

I don't have any implementation my BaseVC. It's just a plain VC.

推荐答案

这是您的问题
self.delegate实际上是一个setter,这就是为什么你骑自行车。
您应该在设置器中使用_delegate = del。

here is your problemself.delegate is actually a setter, that is why you have cycling.You should use _delegate = del inside of your setter.

这篇关于委托的自定义设置器方法被称为无限次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:53