2010-09-09 95 views
0

我在iPhone应用程序中使用MGTwitterEngine来简单调用用户状态。引擎有一个代表方法:从MGTwitterEngine返回状态

- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier 

而且我可以看到我的状态记录在控制台中。我的问题是,什么是最好的方式来使用状态,并在收到它们时得到通知?

我怀疑这可能是更多关于如何正确使用委托模式。

感谢,

+0

我已经部分解决了这个使用NSNotifications。 \t NSNotification * notification = [NSNotification notificationWithName:@“tweetsArrived”object:self]; 有没有更好的方法? – codecowboy 2010-09-09 11:33:28

回答

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. 
}