2010-09-09 37 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. 
}