开发者

Editable UITableView

开发者 https://www.devze.com 2023-02-08 11:39 出处:网络
I\'m trying to set up a UITableView that I can edit. I have the following methods implemented: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

I'm trying to set up a UITableView that I can edit. I have the following methods implemented:

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

but I'm not sure how to link editing to an edit button in my UINavigationBar. Here is my button item:

UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit开发者_StackOverflow社区"
                                                                style:UIBarButtonSystemItemEdit 
                                                               target:nil 
                                                               action:@selector(editButtonSelected:)];

How do I get this working?


I have had a lot of success just using the standard edit button:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

The problem with your code is that you didn't set a target. If the editButtonSelected: selector is in the view controller where you are setting this up, use "self" like this:

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号