Iphone 在UITableView中加载数据,就像在iBooks搜索表中一样
添加一些新数据时,如何让UITableView重新呈现自身? 我正在执行这个代码ib loadView方法Iphone 在UITableView中加载数据,就像在iBooks搜索表中一样,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,添加一些新数据时,如何让UITableView重新呈现自身? 我正在执行这个代码ib loadView方法 [NSThread detachNewThreadSelector:@selector(addSomeData) toTarget:self withObject:nil]; 这是addSomeData方法: -(void)addSomeData{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for (int
[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;
}
-(void)addSomeData{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
对于(int i=1;i尝试:[self.tableView reloadData];
[self.tableView reloadData]
方法是一种完全重新加载表的解决方案,而[self.tableView insertRowAtIndexPath:withAnimation]
是另一种只插入新行并设置更改动画的解决方案