[英]data loading in UITableView like in iBooks search table
添加一些新數據時,如何告訴UITableView重新呈現自身? 我正在執行此代碼ib loadView方法。
[NSThread detachNewThreadSelector:@selector(addSomeData) toTarget:self withObject:nil];
這是addSomeData方法:
-(void)addSomeData{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (int i = 1; i <= 100; i++) {
[myArray addObject:[NSString stringWithFormat:@"Page %i",i]];
NSDate *d2 = [NSDate dateWithTimeIntervalSinceNow:0.2f];
[NSThread sleepUntilDate:d2];
}
[pool release];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *string = [myArray objectAtIndex:indexPath.row];
cell.textLabel.text = string;
// Configure the cell...
return cell;
}
myArray是包含字符串的NSArray。 所以主要問題是-當我向myArray添加新的NSString時如何動態更新tableview?
[self.tableView reloadData]
方法是一種完全重新加載表的解決方案,而[self.tableView insertRowAtIndexPath:withAnimation]
是僅插入新行並對更改進行動畫處理的另一種解決方案。
試試: [self.tableView reloadData];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.