私はタイマーによって呼び出されるメソッドによって更新したい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;
}
私はviewDidLoad
にアレイとself.listData = array
を置けば、それは動作しますが、繰り返すことはしません。私のメソッドpopulateTable
が呼び出されていますが、実際には何もテーブルに入れていません。これは初めてのUITableViewを使用しているので、どのように動作するか分かりません。私はチュートリアルに従うことでこれを多くしました。メソッドを使用してデータを生成するにはどうすればよいですか?
こんにちは、この古い質問では、近代的なアプローチへのポインタhttp://stackoverflow.com/ a/25604378/294884誰かを助けることを願って – Fattie