2012-04-18 91 views
1

我现在用的UITableView工作,我的有什么表视图不显示数据,iphone

MyClass.h

@interface MyClass的:的UIViewController {

}

@property(strong,strong)UILabel * name;

@property(strong,strong)UILabel * add;

MyClass.m

- (NSInteger的)的tableView:(UITableView的*)atableView numberOfRowsInSection:(NSInteger的)部分{

return 3 ; 
} 

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

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

return tableCell; 

}

当我把我在numberOfRowsInSection破发点,似乎是根本没有被执行的时候。 现在令我困惑。 如果您以前遇到过,请咨询。

感谢

+0

请在发布前修改你的代码。你的''@ property''在错误的地方。你用点省略的代码对于显示内容起着重要作用。 – 2012-04-18 00:39:22

+0

我刚刚编辑...第一件事,我只是想确保numberOfRowsInSection正在执行或不。否则,显示是没有什么.... – tranvutuan 2012-04-18 00:49:05

回答

3

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

否则,将其设置在这样的代码:

self.tableView.delegate = self; 
self.tableView.datasource = self; 
+0

感谢提醒我。我刚刚回头看storyBoard,并意识到我没有将dataSource和委托设置到tableView。 – tranvutuan 2012-04-18 00:52:15