我尝试在表格 View 中显示数组对象。 这是一个单屏应用程序,我正在使用 Storyboard。 运行时 - tableview 显示为空网格。不显示对象的数据。什么可能导致这个? 有 2 个必需的方法 numberOfRowsInSection 和 cellForRowAtIndexPath 我怀疑是最后一个。 .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/