0

我的问题是如果行返回 5 然后UITableView显示 0 到 5 索引,但我们想要打印 3 到 5 的任何逻辑??` // 创建单元格标识符 static NSString *CellIdentifier = @"CellIdentifier";

// Create the cell if cells are available with same cell identifier
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// If there are no cells available, allocate a new one with Default style
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [[no objectAtIndex:indexPath.row]valueForKey:@"name"];
// Configure cell...

我可以打印值自定义范围吗

4

1 回答 1

0

您的解决方案是这样的,它运行良好:

在.h

Bool drawCell;

- (void)viewDidLoad
{
drawCell=NO;
}    
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{        
UITableViewCell *cell = nil;
if(indexPath.row==3)
{
 drawCell=YES;
}
if(drawCell)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.textLabel.text = [[no objectAtIndex:indexPath.row]valueForKey:@"name"];
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    cell.frame=CGRectMake(0, 0, 0, 0);
}

return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (drawCell) {
    return 100.0f;
} else {
    return 0.0f;
}
}
于 2013-03-08T11:13:25.420 回答