这是 cellForRowAtIndexPath: 方法的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
当我使用 [self.tableView reloadData];
什么都没发生?
最佳答案
您至少需要实现 tableView:numberOfRowsInSection:方法作为 UITableViewDataSource 协议(protocol)的一部分,以及 tableView:cellForRowAtIndexPath:
(您已经这样做了)。您还应该实现 numberOfSectionsInTableView:
。
然后你需要确保你的类确实被用作数据源:
self.tableView.dataSource = self;
这需要通过 Interface Builder 或在 awakeFromNib
或其他一些方法(如 viewDidLoad:
)中完成。
关于iphone - 为什么 [self.tableView reloadData] 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5349162/