这是我第一次使用 Storyboard 构建应用程序。我正在尝试使用自定义单元格创建 UITableView。我在 IB 中创建了单元格并为其创建了自定义 tableViewCell 类(添加了一些标签,创建了适当的插座,在 IB 中连接它们并将自定义类分配给 IB 中的自定义单元格)。
在负责 TableView 的 ViewController 中,我创建了数据源(带有一些数组的 dict)并填写了所有必需的方法(我已经尝试使用 UITableViewControler 和设置为 tableview 的委托和数据源的 UIViewController )
当我运行应用程序时 - 表格视图是空的。在做了一些 NSLogging 之后,我注意到数据源方法永远不会执行。我不知道为什么。
我现在为此疯狂了几个小时。请帮帮我:)
如果您需要查看代码或情节提要或其他任何内容,请告诉我。
更新:好的,经过一番挖掘,我决定测试相同的代码,但使用 NSMutableArray 作为数据源而不是 NSMutableDictionary。它有效!现在,有人可以向我解释为什么它不适用于 dict 吗?
这是做了什么。我有一个包含 5 个数组的字典,每个数组有 5 个字符串。
在 numberOfRowsForSection 方法中,我返回了 [dict count]
在 cellForRowAtIndexPath 方法中,我使用了这段代码
NSArray * routeArray = [dealsDict objectForKey:@"route"];
cell.routeName.text = [routeArray objectAtIndex:indexPath.row];
NSArray * companyArray = [dealsDict objectForKey:@"company"];
cell.companyName.text = [companyArray objectAtIndex:indexPath.row];
NSArray * priceArray = [dealsDict objectForKey:@"price"];
cell.priceLabel.text = [priceArray objectAtIndex:indexPath.row];
NSArray * dateArray = [dealsDict objectForKey:@"date"];
cell.dateLabel.text = [dateArray objectAtIndex:indexPath.row];
NSArray * monthArray = [dealsDict objectForKey:@"month"];
cell.monthLabel.text = [monthArray objectAtIndex:indexPath.row];
NSLog(@"I'm in here");
return cell;
为什么它不想显示任何东西?