我的tableview中的单元格不会显示任何内容。Objective c UITableViewCell不显示内容
- (void)viewDidLoad {
[super viewDidLoad];
testArray = [[NSMutableArray alloc] init];
}
如果按钮被点击,应用程序将转到下一个屏幕并显示表格。 (日志显示testString被存储到testArray中)
- (IBAction)goNext:(id)sender {
for(int i=0; i<10; i++){
NSString *testString = @"Hello";
[testArray addObject:testString];
NSLog(@"myArray:\n%@", testArray[i]);
}
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"test"];
[self presentViewController:vc animated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return testArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
cell.textLabel.text = testArray[indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", (int)indexPath.row + 1];
return cell;
}
如果我这样做,将显示内容。
- (void)viewDidLoad {
[super viewDidLoad];
[self testArraySetup];
}
- (void)testArraySetup{
testArray = [NSMutableArray arrayWithArray:@[@"Pizza",@"Bread",@"Drinks"]];
}
任何意见是非常感谢。
你在哪里调用'reloadData'? – rmaddy
'[tableView reloadData];'或者检查'delegate'和'dataSource' – Rin
问题已更新,请再次检查。 – bubibu