我的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