2

我正在实施commitEditingStyle:。当我点击导航栏上的编辑按钮时,滑动删除按钮将到达,一切正常。问题是,当我单击“编辑”时,我想将该按钮更改为“完成”,当我单击“完成”时,表格视图单元格上的那些删除按钮应该消失,我该怎么做,我是新手,请指导我在哪里做错了。

代码片段如下所示:-

- (void)viewDidLoad
{       
     UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
     NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

     UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(ComposeBtn)];
     bi.style = UIBarButtonItemStyleBordered;
     [buttons addObject:bi];
     [bi release];

     bi = [[UIBarButtonItem alloc]
          initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
     [buttons addObject:bi];
     [bi release];

     bi = [[UIBarButtonItem alloc]
          initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(setEditing:)];
     bi.style = UIBarButtonItemStyleBordered;
     [buttons addObject:bi];
     [bi release];

     [tools setItems:buttons animated:NO];
     [buttons release];

     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
     [tools release];
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
   // Return NO if you do not want the specified item to be editable.
    return YES;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.listOfFilesTblView setEditing:editing animated:animated];
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return UITableViewCellEditingStyleDelete;
}

如果我使用下面的代码行,一切都可以正常工作。

self.navigationItem.rightBarButtonItem=self.editButtonItem;

但我想要导航栏上的 2 个按钮,1)编辑 2)撰写。请指导我在这里缺少什么。在此先感谢。

4

0 回答 0