我在 iPhone 应用程序中使用 MGTwitterEngine 对用户状态进行简单调用。引擎有一个委托方法:
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier
我可以在控制台中看到我的状态。我的问题是使用状态并在收到状态时得到通知的最佳方法是什么?
我怀疑这可能更多地是关于如何正确使用委托模式。
谢谢,
我在 iPhone 应用程序中使用 MGTwitterEngine 对用户状态进行简单调用。引擎有一个委托方法:
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier
我可以在控制台中看到我的状态。我的问题是使用状态并在收到状态时得到通知的最佳方法是什么?
我怀疑这可能更多地是关于如何正确使用委托模式。
谢谢,
I went with setting up an NSNotification observer and then calling that from statusesReceived:forRequest. I also set an NSArray iVar in the delegate method which I access in my NSNotification callback:
[[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.
}