【问题标题】:table view does not display data,iphone表格视图不显示数据,iphone
【发布时间】:2012-04-29 09:04:53
【问题描述】:

我现在正在使用 UITableView,我拥有的是

MyClass.h

@interface MyClass : UIViewController {

}

@property (strong , strong) UILabel *name;

@property (strong , strong) UILabel *add;

MyClass.m

-(NSInteger)tableView:(UITableView *)atableView numberOfRowsInSection:(NSInteger)section{

return 3 ;
 }

-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"cell";
tableCell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
...................................................

return tableCell; 

}

当我在 numberOfRowsInSection 处设置断点时,它似乎根本没有被执行。 现在让我很困惑。 有遇到过的请指教。

谢谢

【问题讨论】:

  • 请在发布前修改您的代码。你的@property 放错地方了。您用点省略的代码对显示的内容起着重要作用。
  • 我刚刚编辑了...我只想确保 numberOfRowsInSection 是否正在执行的第一件事。否则,显示什么都不是……

标签: iphone objective-c ios cocoa-touch


【解决方案1】:

最常见的原因是没有将视图控制器设置为表视图委托和数据源。如果它内置在故事板中,您可以通过选择表格上的连接检查器并将这些属性拖到视图控制器来执行此操作。

否则,在代码中设置如下:

self.tableView.delegate = self;
self.tableView.datasource = self;

【讨论】:

  • 谢谢提醒。我刚刚回顾了storyBoard,意识到我没有设置dataSource并委托给tableView。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-06
  • 2012-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多