简体   繁体   中英

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?

Try this: Incorporate the tableView datasource method for row height.

-(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". 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. Try this:

data = [array objectAtIndex:indexPath.row];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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