我在 UIView 中创建了一个 UITableView,只使用代码(不使用 IB)
m_tableData = [[UITableView alloc] init];
m_tableData.dataSource = self;
m_tableData.delegate = self;
[self addSubview:m_tableData];
和
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d", [arrPanelListImg count]);
return [arrPanelListImg count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kCell"] ;
NSLog(@"%d", indexPath.row);
}
return cell;
}
在日志屏幕中我看到
numberOfRowsInSection: 方法返回 18。而 cellForRowAtIndexPath: 方法,只需运行 9 次(适合屏幕)。
而且我在我的代码中没有发现任何奇怪的地方。所以在这种情况下,有人对我有任何建议。先谢谢了。