ios - 使用 Storyboard的 UItableView 的空网格

标签 ios objective-c uitableview storyboard xcode5

我尝试在表格 View 中显示数组对象。 这是一个单屏应用程序,我正在使用 Storyboard。 运行时 - tableview 显示为空网格。不显示对象的数据。什么可能导致这个? 有 2 个必需的方法 numberOfRowsInSectioncellForRowAtIndexPath 我怀疑是最后一个。 .h 文件包含此行:

@interface MYViewController : UIViewController  <UITableViewDataSource, UITableViewDelegate> 

我按照您的建议通过代码设置委托(delegate)和数据源。仍然是空的网格。

这是我的实现: -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 返回 [listRecipes.recipeArray count]; }

-(UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString cellIdentifier = @"ListCellIdentifier"; MYCustomListCell* listCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; NSString* dataString = listRecipes.recipeArray[indexPath.row]; listCell.listName.text = dataString; listCell.imageView.image = [UIImage imageNamed:dataString]; return listCell; } 

我尝试在 MVC 中显示数组中的数据。 如果数组是本地的——显示数据

你能告诉我该怎么做吗? 先谢谢你。

最佳答案

永远记住连接表的委托(delegate)和数据源。

作为符合这两个协议(protocol)的 UIViewController 上的 UIElement 不足以让 Xcode 假定 UIViewController 应该是表的委托(delegate)和/或数据源。

右键单击您的表格 View ,从委托(delegate)和数据源拖动到您的 UIViewController。

您还可以通过以下方式以编程方式设置这些:

self.table.datasource = self;
self.table.delegate = self;

如果在此之后您仍然遇到问题,则必须向我们展示您是如何实现数据源协议(protocol)方法的。

关于ios - 使用 Storyboard的 UItableView 的空网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21210040/

相关文章:

ios - 在 iOS 中执行大量服务器请求的并发队列与串行队列

ios - 如何从 UISearchBar 移动占位符标签

ios - subview Controller 中的 UITableView 委托(delegate)

ios - Firebase/Swift - 从 Firebase 输出数据出错

ios - 如何将 ScrollView 锁定到位?

ios - 应用程式因服务回应而当机

ios - 如何更改 UILabel swift 中文本的行距

ios - 为什么将 char 数组转换为字符串会创建一个 nil 字符串?

objective-c - 崩溃的突然尖峰总是在同一行上

ios - iOS 11 不再支持将图案颜色设置为 UITableViewRowAction 的 backgroundColor