我有一个UITableView,我想通过定时器调用的方法进行更新。我现在拥有的是:连续填充tableview
-(void) populateTable {
NSLog(@"done");
NSArray *array = [[NSArray alloc] initWithObjects:@"ob 1",@"ob 2",@"ob 3",nil];
self.listData = array;
[array release];
}
- (void)viewDidLoad {
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(populateTable) userInfo:nil repeats:YES];
[super viewDidLoad];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
如果我把阵列和self.listData = array
到viewDidLoad
它的工作原理,但不会重复。我的方法populateTable
正在被调用,但实际上并没有在桌子上放置任何东西。这是我第一次使用UITableView,所以我不太了解他们的工作方式。我按照教程做了很多。如何使用一种方法来填充数据?
嘿 - 在这个老问题上,对于googlers这里是一个指向现代方法的指针http://stackoverflow.com/ a/25604378/294884希望它可以帮助某人 – Fattie 2014-09-03 08:21:34