PDA

View Full Version : questino about the Edit button




tranvutuan
Feb 3, 2012, 01:08 PM
I am adding a Edit button to the top right corner of tool bar by doing this

- (void)viewDidLoad
{
NSLog(@"VIEW DID LOAD");
[super viewDidLoad];
// Initialize var

self.navigationController.navigationBarHidden = NO;
self.navigationItem.hidesBackButton = NO;

self.navigationItem.rightBarButtonItem = [self editButtonItem];
}

Also, the documentation indicated that
Name:editButtonItem - (UIBarButtonItem *)editButtonItem
Availability: iOS (2.0 and later)
Abstract: Returns a bar button item that toggles its title and associated state between Edit and Done.
However, when i run the program and try to click on EDIT button. It is changed to DONE but the each row of my table does not have any red circle with (-) before...

Please guide me on this issue. Thanks



phantax
Feb 3, 2012, 01:25 PM
Have you implemented the method which actually allows editing of your UITableView?

tranvutuan
Feb 3, 2012, 01:32 PM
Have you implemented the method which actually allows editing of your UITableView?
Yes I did and here it is

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

if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"JUST DELETE AN ITEM AT %d",[indexPath row]);
[myTableView reloadData];
}

}

phantax
Feb 3, 2012, 01:46 PM
Is your controller acting as a UITableViewController in your header file?

Is this ViewController also your data source?
If so, is it working correctly to load data into the cells as you expect?

tranvutuan
Feb 3, 2012, 02:16 PM
Is your controller acting as a UITableViewController in your header file?

Is this ViewController also your data source?
If so, is it working correctly to load data into the cells as you expect?

What i have is

@interface myClass : UIViewController <UITableViewDataSource,UITableViewDelegate>
........
........
........
@end
I also attach 2 images from from xib so you can know what I am doing now.

phantax
Feb 3, 2012, 02:47 PM
Your class is a UIViewController and not a UITableViewController so you are basically expecting to gain some functionality for free.

There are some things that a UITableViewController will do for you automatically, which will not happen in this case, one of which happens to be toggling the edit mode of a TableView.

If you aren't doing anything out of the ordinary, I would recommend you subclass UITableViewController. Otherwise, look into the "setEditing" method for UITableView to do it yourself.

tranvutuan
Feb 4, 2012, 09:35 AM
Your class is a UIViewController and not a UITableViewController so you are basically expecting to gain some functionality for free.

There are some things that a UITableViewController will do for you automatically, which will not happen in this case, one of which happens to be toggling the edit mode of a TableView.

If you aren't doing anything out of the ordinary, I would recommend you subclass UITableViewController. Otherwise, look into the "setEditing" method for UITableView to do it yourself.

is the setEditing from system or we have to provide one.

PhoneyDeveloper
Feb 4, 2012, 10:46 PM
You need to provide one. Call [super setEditing:edit] and [self.tableView setEditing:edit] It is this second call that you're missing.