UITableViewSection Row Indices

后端 未结 2 1868
情歌与酒
情歌与酒 2021-01-26 02:26

I have a UITableView with three sections (Friday, Saturday, Sunday) each with different data and a different number of rows. When selected, the selected row expands, but so do t

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-26 02:40

    Save the index path as your selection instead of just the row. At the moment you are saving, say, row 2, and each section has a row 2, so that row is expanding in all sections.

    You can compare index paths as follows:

    if([indexPath1 isEqual:indexPath2])
        // Do your thing
    

    Better yet, UITableView has an indexPathForSelectedRow property, so you don't even need your own variable to keep track of this:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    int rowHeight;
    if ([indexPath isEqual:tableView.indexPathForSelectedRow]) {
        rowHeight = 185;
    } else rowHeight = 44;
    return rowHeight;
    }
    

提交回复
热议问题