简体   繁体   English

iOS:在uitableview中跳一个位置

[英]IOS: jump a position in a uitableview

in method 方法中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

usually you use an array to set 通常您使用数组来设置

[cell.textLabel setTex:@"row"];

but if I want to jump a row? 但是如果我想跳一下呢?

at example at indexpath.row I don't want to have this cell in my tableview, is possible? 例如在indexpath.row上,我不想在表格视图中使用此单元格,可以吗?

Try this: Incorporate the tableView datasource method for row height. 尝试以下操作:为行高合并tableView数据源方法。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == NUMBER_TO_AVOID) {
        return 0.0f;
    }
    return 44.0f; //standard cell height
}

I have done this in several similar situations. 我在几种类似的情况下都这样做。 What you'll do is create a second array "activeItems". 您将要做的是创建第二个数组“ activeItems”。 Or something like that. 或类似的东西。 Iterate through your main data array and build the active array with the valid items. 遍历您的主数据数组,并使用有效项构建活动数组。 Than have your data source reference this array instead. 而不是让您的数据源引用此数组。 This gives you an array that is accurately indexed to your table. 这为您提供了一个可以准确索引到表的数组。

You can put a condition in cellForRowAtIndexPath. 您可以在cellForRowAtIndexPath中放置一个条件。 Try this: 尝试这个:

data = [array objectAtIndex:indexPath.row];

If (data != nil){
    [cell.textLabel setText:data];
}
else{
    // code that handles data if null
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM