开发者

Delegate seems to be set to nil automatically

开发者 https://www.devze.com 2023-03-01 00:26 出处:网络
I am making a helper class. This helper class consists of a NSObject class which I would interact with and a UIViewController that does some other stuff.

I am making a helper class. This helper class consists of a NSObject class which I would interact with and a UIViewController that does some other stuff.

Here i开发者_运维知识库s what happens, in my app delegate or wherever I allocate my NSObject class:

MyObjectClass *class = [[MyObjectClass alloc] init];
[class setDelegate:self];

Now, this delegate is something I created like this:

@protocol MyDelegate
-(void) someCall;
@end
@interface MyHelperClass : NSObject {
    id <MyDelegate> delegate;


}
@property (retain, nonatomic) id <MyDelegate> delegate;

So this works great. But here's the problem. If I allocate my helper class and set it's delegate to a view controller or something and then call one of my methods that open my helper view controller the delegate stops working. After debugging it seems it has some memory address until I pop up the other view controller and when I return to it, the memory address of the delegate is 0x0.

My questions is how could this happen? Do I need to do something special with my delegate to stop it from releasing? (I don't release it anywhere myself) Do I need to retain it? How do I keep it allocated even when I open my viewcontroller so I can continue using it?

Thanks in advance!


the memory address of the delegate is 0x0 means that it was never assigned, not that it was released. if it was released it wouldn't be a valid address anymore, but it would be the same address that it was before it was released.

0

精彩评论

暂无评论...
验证码 换一张
取 消