【发布时间】:2012-10-11 17:53:21
【问题描述】:
我在一个视图中有 3 个表视图,我想知道为什么 tableView:cellForRowAtIndexPath: 没有被调用。
#pragma mark -
#pragma mark <UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.mainVoucherTableViewController)
[self setSelectedIndex:indexPath.row];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.mainVoucherTableViewController){
return 10;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.mainVoucherTableViewController){
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell.textLabel.text = @"THISTEXT";
return cell;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView == self.mainVoucherTableViewController)
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// The header for the section is the region name -- get this from the region at the section index.
if (tableView == self.mainVoucherTableViewController){
NSString * myString = [NSString stringWithFormat:@"HELLLO WORLD"];
return myString;
}
}
有人知道这是为什么吗?基本上这不会创建任何单元格或显示单元格。它只显示表格视图。 :(
【问题讨论】:
-
检查表和它的数据源之间的连接。
-
您使用的是
UITableViewController还是UIViewController?如果后者是您的 tableview 与您在 IB 中的委托和数据源挂钩? -
仔细检查您的
UITableViews 的数据源和委托已通过插座链接或代码设置。 -
我猜您是在将视图与
tableView == self.mainVoucherTableViewController中的控制器进行比较? -
@iBlue 我正在通过 UIViewController 中的代码创建 UITableView,
标签: iphone objective-c ios uitableview ios4