[英]Updating TableView of Blog Articles Issue
我正在嘗試使用一個博客應用程序刷新文章,並添加自上次發布以來可能已經寫過的所有新文章。
TableView使用數組_allEntries。 有人告訴我,當用戶單擊“刷新”按鈕時,我應該清除該數組,清除后,運行原始的啟動代碼來解析rss並重新填充表視圖。 我這樣做是:
[_allEntries removeAllObjects];
[self refresh];
但是,當我這樣做時,它崩潰並顯示錯誤:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds for empty array'
關於我在做什么錯有什么想法嗎?
編輯:這是我的viewDidLoad和刷新代碼,以及更新代碼。
- (void)viewDidLoad { [super viewDidLoad];
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:@"feedurlhere", nil];
[self refresh];
}
- (void)refresh {
for (NSString *feed in _feeds) {
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}
}
-(void)updatearticle {
[_allEntries removeAllObjects];
[self refresh];
}
它在您首次加載時起作用,因為在調用刷新之前,Feed已填充在viewDidLoad方法中。 當您刪除所有對象然后調用refresh時,數組中沒有任何內容,因此出現了越界錯誤。 您應該將所有代碼([自我刷新除外])移出viewDidLoad並移入refresh方法。
如果_allEntries
用作表視圖的數據源,則必須在[_allEntries removeAllObjects]
之后調用[self.tableView reloadData]
[_allEntries removeAllObjects]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.