开发者

What is a safe way to check for a protocol response

Here's a scenario:

A view controller pushes a new controller to the nav controller. This child controller creates a model that uses a NSURLConnection. When this connection fin开发者_开发问答ishes it will make a call like the following:

[self.delegate modelDidFinishParsing:self];

What is the safe way to produce this code? Right now, I have this code and it crashes in a certain situation:

if ([self.delegate conformsToProtocol:@protocol(ModelDelegate)]) [self.delegate modelDidFinishParsing:self];

The situation when it crashes is when the view controller that owns the model is popped from the stack before the model finishes. Should I make the model an ivar so that the controller releases it in its own - (void)dealloc ?


In your check, you could make sure the delegate isn't nil

if (self.delegate && [self.delegate conformsToProtocol...]) [self.delegate modelDidFinishParsing:self];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜