我有一個具有UITableView的應用程序。這個UITableView被一個NSMutableArray填充(作爲一個屬性)在appDelegate中。您可以將其視爲電子郵件窗口。它在子類UITableViewCell中列出消息。當出現一條新消息時,我會完成所有下載消息的代碼,並將數據添加到包含所有消息的appDelegate的NSMutableArray中。此代碼工作正常。什麼是[UITableView reloadData]?
現在,一旦新消息被下載並添加到數組中,我試圖用下面的代碼更新我的UITableView,但是 - UITableView的委託函數不會被調用。
奇怪的是,當我向上和向下滾動我的UITableView時,委託方法終於被調用,並且我的節標題發生改變(它們顯示該節的消息計數)。他們不是實時更新,而是不等我滾動觸發刷新?此外,新的細胞永遠不會添加在該部分!
請幫忙!!
的appdelegate CODE:
[self refreshMessagesDisplay]; //This is a call placed in the msg download method
-(void)refreshMessagesDisplay{
[self performSelectorOnMainThread:@selector(performMessageDisplay) withObject:nil waitUntilDone:NO];
}
-(void)performMessageDisplay{
[myMessagesView refresh];
}
的UITableViewController代碼:
-(void) refresh{
iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate];
//self.messages is copied from appDelegate to get (old and) new messages.
self.messages=mainDelegate.messages;
//Some array manipulation takes place here.
[theTable reloadData];
[theTable setNeedsLayout]; //added out of desperation
[theTable setNeedsDisplay]; //added out of desperation
}
哥們我覺得你的痛苦,在這裏同樣的問題。 – 2011-04-13 06:21:53