如何在添加一些新數據時告訴UITableView重新呈現自己? 我正在執行此代碼ib loadView方法。像在iBooks搜索表中一樣在UITableView中加載數據
[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的IST NSArray的是其中包含的字符串。 所以主要的問題是 - 如何動態更新tableview,當我添加新的NSString myArray?