我在iPhone应用程序中使用MGTwitterEngine来简单调用用户状态。引擎有一个委托方法:
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier
我可以在控制台中看到我的状态。我的问题是,什么是使用状态的最佳方式,并在收到状态时得到通知?
我怀疑这可能更多地是关于如何正确使用委托模式。
谢谢,
答案 0 :(得分:0)
我设置了一个NSNotification观察者,然后从statusesReceived:forRequest调用它。我还在委托方法中设置了NSArray iVar,我在NSNotification回调中访问该方法:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tweetNotificationHandler:) name:@"tweetsArrived" object:nil];
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier{
tweets = statuses; //this is an ivar
NSNotification* notification = [NSNotification notificationWithName:@"tweetsArrived" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
-(void)tweetNotificationHandler: (NSNotification*)notification {
//do your results handling here.
}