开发者

UITableView Grouped - Select multiple rows

I have a grouped UITableView and want to select some rows. Hers some handy code I found to select multiple rows but for a ungrouped view.

--->

When I'm selecting a row it selects this row of every section.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    cell.acc开发者_JAVA百科essoryType = UITableViewCellAccessoryNone;
} else {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}}

Any help ? Thanks in advance!


Have a look at - iPhone: How to allow multiple selection in tabelview for a custom cell?. If you just set the accessory type as you have done in your code, the accessories won't be maintained when the cells are recycled (when the table is scrolled). Instead you should do something like the following-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //... your existing code ...
    if(self.selectedIndexPaths && [self.selectedIndexPaths containsObject:indexPath]) //selectedIndexPaths is explained in the link above
       cell.accessoryType = UITableViewCellAccessoryCheckmark;
    else
       cell.accessoryType = UITableViewCellAccessoryCheckmark;

    //... your existing code ...
    return cell;
}

This way, you can maintain which cells are selected.

HTH,

Akshay


i think you have taken multiple tables in on view for this differentiate tableviews like

if(tableView = firstTbl){


}
if(tableView = secondTbl){


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜