我对 iOS 编程非常陌生,只是尝试设置一个选项卡视图,包括一个普通视图和一个表格视图。
现在有一个问题,表格视图不会更新。所有单元格始终为空。
这就是我声明 ViewController 的方式:
@interface SecondViewController : UITableViewController {
根据我的日志,所有代表都被正确调用,甚至我在此方法中的日志也被打印到控制台。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CooperCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CooperCell"];
}
NSLog(@"test");
cell.textLabel.text = @"test";
return cell;
}
“测试”是记录 3 倍,因为我的数组大小为 3。所以我不明白为什么它不会显示。当然,我通过情节提要为单元格赋予了标识符“CooperCell”。我错过了其他要链接的东西吗?
我的 SecondViewController.h 看起来像这样:
@interface SecondViewController : UITableViewController {
NSManagedObjectContext *managedObjectContext;
NSMutableArray *eventArray;
}
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, strong) NSMutableArray *eventArray;
- (void) fetchRecords;
@end
我正在使用本教程:http: //mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
也许我真的把故事板搞砸了?
我创建了一个新的 Tab 控制项目。然后我删除了第二个视图控制器并放置了一个 TableViewController 并继续使用我的 SecondViewController.h 和 .m 文件