Objective c 如何处理不同的indexPath?

Objective c 如何处理不同的indexPath?,objective-c,ios,uitableview,ios4,Objective C,Ios,Uitableview,Ios4,让我们看看tableview的一些标准代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; static int count = 0; UITableViewCell *cell = [tableView dequeueReusa

让我们看看tableview的一些标准代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
    static int count = 0;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        NSLog(@"count %d", count++);
    }
    // Configure the cell...
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    return cell;
}
若数组中有10个项,那个么它将为每个indexath.row分配10个单元格

我的问题是 函数reuseIdentifier:CellIdentifier如何知道不同的行?

如果数组中有10个项目,那么 将为每个单元分配10个单元 indexPath.row

这不是真的-通常分配的单元格数为NumberOfVisibleRows+2(或类似值)

UITableView大致就是这样工作的:一旦某个单元格被滚动出可见区域,它就会从UITableView层次结构中删除(将表的clipToBounds属性设置为NO,您就可以看到!),并被放入某种内部缓存中
dequeueReusableCellWithIdentifier:
方法检查缓存中是否有可重用的单元并返回它(如果没有可用的单元,则返回nil)——所以您不需要分配比实际适合可见区域更多的单元


dequeueReusableCellWithIdentifier
方法不依赖于当前的indexPath,而是依赖于传递给它的单元格字符串标识符。indexPath仅用于向单元格获取适当的内容。

哦,方法
**dequeueReusableCellWithIdentifier**:
与indexPath无关

在使用UITableView时,我们使用
[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault]reuseIdentifier:cellIdentifier]
将一类非常重要的单元格放入缓存(可能是一个NSMutableDictionary),并使用键“cellIdentifier”。然后,当我们还需要一个单元格时,我们首先查询缓存,如果没有找到,我们会创建一个新的

索引是编码者处理的责任。可以将不同类型的单元格按部分分开,并在一个部分中逐行显示单元格。节和行组成一个nsindepath