iOS TableView 不显示数据(调用委托(delegate))

标签 ios objective-c uitableview delegates

我是 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 文件。我们将能够提供更多帮助。

enter image description here

关于iOS TableView 不显示数据(调用委托(delegate)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673933/

相关文章:

iphone - 搜索 ABAddressBook 时,如何在排除职位名称的同时搜索联系人姓名?

ios - 将更改上传到解析 PFUser 对象不起作用

ios - SiriKit:自定义意图 - 本地化问题

objective-c - 如何在不进入编辑模式的情况下直接编辑UITableView中的一行

swift - 如何在另一个 TableView 单元格内添加带有按钮的 TableView 单元格?

ios - 线程 5 : EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) - 从 'Result<AnyObject>' 转换为无关类型 'NSDictionary' 总是失败

iphone - 如何为表格中的每个部分添加标题标题

ios - iOS 8.1 下 UIPopoverController 出现不可预知的延迟

ios - 使用 Swift 在 TableView 中显示 JSON 数据

objective-c - 没有可见的@interface