【问题标题】:empty grid of UItableView using storyboard使用情节提要的 UItableView 的空网格
【发布时间】:2014-02-08 05:00:12
【问题描述】:

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

@interface MYViewController : UIViewController  <UITableViewDataSource, UITableViewDelegate> 

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

这是我的实现: -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [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 中显示数组中的数据。 如果数组是本地的 - 显示数据

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

【问题讨论】:

    标签: ios objective-c uitableview storyboard xcode5


    【解决方案1】:

    永远记得连接你的表的委托和数据源。

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

    右键单击您的表格视图,从委托和数据源拖动到您的 UIViewController。

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

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

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

    【讨论】:

    • 这应该被编辑到问题中——不要粘贴为 cmets。
    【解决方案2】:

    检查您的 tableview 委托和数据源的初始化是否在 recipeArray 初始化之前。在这种情况下,您必须在将项目添加到 recipeArraytableView.reload()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      相关资源
      最近更新 更多