Reputation: 2451
I am working on the app which contains one of the grouped section UITableView with edit/delete functionality. Tableview is looked like this
-(IBAction) EditTable:(id)sender
{
if (self.editing)
{
[super setEditing:NO animated:NO];
[libtable setEditing:NO animated:NO];
[libtable reloadData];
[tabledit setTitle:@"Edit" forState:UIControlStateNormal];
}
else
{
[super setEditing:YES animated:YES];
[libtable setEditing:YES animated:YES];
[libtable reloadData];
[tabledit setTitle:@"Done" forState:UIControlStateNormal];
}}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self delete];
}
}
On the very first row of each section I have disable the editing mode with this method:
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return indexPath.row > 0;}
It is working fine but you can see in this image :
The very first row of each section because of non-editable mode doesn't move to right side when I click on edit mode. I need these 0 index row also in right side on the click of edit button same like other rows. I didn't find any method to resolve this. If anyone has knowledge on this concept please help me out.
Thanks in advance.
Upvotes: 1
Views: 200
Reputation: 8402
Try like below
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0) //for each section of first row return UITableViewCellEditingStyleNone
return UITableViewCellEditingStyleNone;
return UITableViewCellEditingStyleDelete;
}
i forgot see your -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
//you may comment this method
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES; //return for every cell as editable
}
if u run and in editing mode u will get like this
Upvotes: 2
Reputation: 480
try to use below delegate method to decide editing style for cells
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
if(indexPath.row ==0 ){
return UITableViewCellEditingStyleNone;
}else{
return UITableViewCellEditingStyleInsert;
}
}
and change your method canEditRowAtIndexPath to =>
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
Upvotes: 1