У меня есть UITableView, который я хочу обновить методом, вызванным таймером. Теперь у меня есть:
-(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, поэтому я не знаю, как они работают. Я сделал это много, следуя инструкциям. Как можно использовать метод для заполнения данных?