UITableViewCell editing style for specific rows - iphone

I've been trying to delete particular rows in UITableView, using below delegate method
tableView commitEditingStyle:editingStyle forRowAtIndexPath:
My intension is to not to show the "Delete" button for particular cells only.
please any one can help me how to solve this.

Use following Datasource method of UITableView
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the apply specified item to be editable.
if("Your Condition") // such like indexPath.row == 1,... or whatever.
return YES;
else
return NO;
}
In short return YES on specific row/cell which you want to edit otherwise return NO;

Related

How to disable the row selection after specific no of counts in UItableview

I wanted to disable the UITableView cell selection after selecting 10 rows in multiselect UITableView,
After deselecting some rows again user will able to select the UITableView cell.
Can anybody please suggest me, how can i do this?
Thanks for help in advance.
Implement willSelectRowAtIndexPath:indexPath:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.indexPathsForSelectedRows.count < YourMaxRowSelectedCount) {
return indexPath;
} else {
return nil;
}
}
The method indexPathsForSelectedRows returns an NSArray object of index paths of all the selected rows of the table view. You can check count of that to compare to your required number of selected rows and act accordingly.

Exclude UITableViewCell from editing

I have an edit button that when pressed puts the entire table into edit mode: tableView.editing=YES;
I want every cell to be in edit mode except for the last cell, which I want to remain in non-edit mode, always. Is there any way to do this?
Check it out!
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// this logic might work for you, or it mightn't if you have more than one section
return [tableView numberOfRowsInSection:indexPath.section] != (indexPath.row + 1)];
}

How to disable "delete" when the table section is 0 on iPhone?

I have a UITableView with two sections, and I added a edit button. If I press the edit button, I can delete the item on the UITableView, but I wanna to check the if the section is 0, the delete button will not display, how can I handle it for that purpose? Thank you.
Implement the tableView:canEditRowAtIndexPath: method of the table view delegate in your view controller to check for the section. This and other edit methods control both edit and delete capabilities:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
return NO;
}
return YES;
}

How to limit the delete option for first row in UITableView

HI
In my appliacation I want deletion control button will not work for first row except for all other rows.
Please can anybody tell me how it would be possible.
Thanks
Implement editingStyleForRowAtIndexPath method in table delegate and return style value depending on cell's index:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//Disable editing for 1st row in section
return (indexPath.row == 0) ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete;
}

How to prevent UITableView from reserving space at the left of cell when editing is turned on?

I'm set editing mode for UITableView to have a possibility of cell reordering. UITableViewCellEditingStyleNone is returned by editingStyleForRowAtIndexPath: method for every cell, but it reserve some area on the left of cell. Is it possible to prevent such an area reserving, because I'm not need an insert or delete icon on left? In short, i want have a cell that occupate all available area and still can be reordered.
// UITableViewDelegate
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
See the docs: You can set a boolean on the cell to make it not indent. Just add
cell.shouldIndentWhileEditing = NO;
to wherever you create your cell.
Set this to like 2 or 3
tableView:indentationLevelForRowAtIndexPath:
The shouldIndentWhileEditing property only works with grouped tables. I found that setting an indentation level of -3 does the job for plain tables. Is there a better way? Here's what I'm using now:
if (self.tableView.style == UITableViewStylePlain) {
cell.indentationLevel = -3;
} else if (self.tableView.style == UITableViewStyleGrouped) {
cell.shouldIndentWhileEditing = FALSE;
}
Do both
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
and
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
in your UITableViewDelegate. Otherwise the cell content is indented.