I have UITableView
and I am trying to load it by default in edit mode. The problem is when I this line table.editing=TRUE;
my rows disappear, I implemented this methods:
- (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
{
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
but with no luck. What should I do?
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
Configuring rows for the table view. Tells the delegate the table view is about to draw a cell for a particular row. Asks the delegate to return the level of indentation for a row in a given section. Called to let you fine tune the spring-loading behavior of the rows in a table.
as Anish pointed to using
[tableView setEditing: YES animated: YES];
But you need to have it in viewWillAppear
view event to make it work.
try this...
[tableView setEditing: YES animated: YES];
In ViewDidLoad write
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStyleBordered target:self action:@selector(addORDoneRows)];
[self.navigationItem setLeftBarButtonItem:addButton];
addORDoneRow
- (void)addORDoneRows
{
if(self.editing)
{
[super setEditing:NO animated:NO];
[_dbSongsTblView setEditing:NO animated:NO];
[_dbSongsTblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[_dbSongsTblView setEditing:YES animated:YES];
[_dbSongsTblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
For MultipleSelection of Row
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Note: There are Three Editiing Style as below
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
Note: And for multiple Selection set Selection and Editing Style to Multiple from Attribute inspector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With