我是 iOS 编程的新手,只是尝试设置一个选项卡 View ,包括一个普通 View 和一个表格 View 。
现在有一个问题,表格 View 不会得到更新。所有单元格始终为空。
这就是我声明 ViewController 的方式:
@interface SecondViewController : UITableViewController {
根据我的日志,所有委托(delegate)都被正确调用,甚至我在这个方法中的日志也被打印到控制台。
- (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;
}
“test”是 logges 3 次,因为我的数组大小为 3。所以我不明白为什么它不显示。当然,我通过 Storyboard为单元格指定了标识符“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/
也许我真的把 Storyboard搞砸了?
我创建了一个新的 Tab 控制项目。然后我删除了第二个 View Controller 并放置了一个 TableViewController 并继续我的 SecondViewController.h 和 .m 文件
最佳答案
检查您是否已将 Storyboard中的 TableView 连接到 .h 文件中的 IBOutlet 变量 UITablveView。你提到你已经链接了单元格。不确定这是正确的做法。
另一种可能性是您没有将 Storyboard上的 View Controller 标识为您的类名 (SecondViewController)。
如果在尝试/确认这些后仍无法正常工作,请也共享您的 .h 文件。我们将能够提供更多帮助。
关于iOS TableView 不显示数据(调用委托(delegate)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673933/