我在一個UIView創建一個UITableView,只使用代碼只(不使用IB)iOS版 - UITableView的工作numberOfRowsInSection之間不正確的:和的cellForRowAtIndexPath:方法
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次(適合屏幕)。
而我在代碼中找不到任何奇怪的東西。所以在這種情況下有人對我有任何建議。 謝謝先進。
這應該是正確的。它不會要求您填充數據,直到需要顯示它們。 –