2014-09-24 92 views
0

下面是代码:的UITableView编辑:细胞的编辑,但删除按钮不会显示出来

-(void)buttonEditPressed:(id)sender{ 

    if(_tableView.isEditing){ 

     [_tableView setEditing:NO animated:YES]; 
     [_buttonEdit setTitle:@"Edit" forState:UIControlStateNormal]; 

    } else { 

     [_tableView setEditing:YES animated:YES]; 
     [_buttonEdit setTitle:@"Done" forState:UIControlStateNormal]; 
    } 

    [_tableView reloadData]; 

} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    DLog(@""); 
    return UITableViewCellEditingStyleDelete; 
} 


- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    //Delete the rows at the Indexpath. 

    //edit data model 

    [_tableView reloadData]; 

} 

这里是结果: enter image description here enter image description here

刷卡删除的作品。然而,当按下编辑按钮时,单元格向右移动,显示左侧红色删除按钮的空间,但该按钮从不出现!

我该怎么办?

回答

0

试试这个库:https://github.com/CEWendel/SWTableViewCell

这是伟大的记录,易于使用和伟大的你想要的东西。

+0

感谢您的建议!我宁愿诚实地手动创建一个按钮,而不是使用一个全新的库= /谢谢你的建议! – stackOverFlew 2014-09-24 09:31:49

+0

你的代码中的问题是,你没有定义左侧的任何视图/按钮。 – 2014-09-24 09:54:59

+0

我该怎么做? – stackOverFlew 2014-09-24 09:57:23