iphone表视图不显示数据

时间:2012-04-18 00:33:18

标签: iphone objective-c ios cocoa-touch

我现在正在使用UITableView,而我正在使用的是

  

MyClass.h

     

@interface MyClass:UIViewController {

     

}

     

@property(强,强)UILabel *名称;

     

@property(强,强)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 时,它似乎根本没有被执行。 现在让我感到困惑。 如果您以前遇到过,请提供建议。

由于

1 个答案:

答案 0 :(得分:3)

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

否则,请将其设置为以下代码:

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