开发者

Multi Select Table View Cell and no Selection Style

开发者 https://www.devze.com 2023-02-08 16:02 出处:网络
I have a basic UITableView that I want to enable the Mail.app style check marks while having no selection style. I have the following snippet:

I have a basic UITableView that I want to enable the Mail.app style check marks while having no selection style. I have the following snippet:

#开发者_如何学Pythondefine UITableViewCellEditingStyleMultiSelect (3)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleMultiSelect;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

However, this will never display the check marks on selection (although the empty circles are displayed). Any ideas on how to fix it? I know it uses undocumented features but I'd really like to add support for the check marks. My actual example uses a very customized UITableViewCell and I can't enable the selection style!

Multi Select Table View Cell and no Selection Style


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

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    if (self.tableView.isEditing) {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    } else {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return cell;
}

-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleMultiSelect;
}

-(IBAction) switchEditing {
    [self.tableView setEditing:![self.tableView isEditing]];
    [self.tableView reloadData]; // force reload to reset selection style
}
0

精彩评论

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