我有一個導航控制器。我想將編輯按鈕放在工具欄的底部而不是頂部導航欄中。在底部工具欄中編輯項Xcode和Objective C
self.navigationItem.leftBarButtonItem = self.editButtonItem;
我遇到的問題是,當我將編輯按鈕添加到底部工具欄。像這樣:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.christmasGifts removeGiftAtIndexPath:indexPath];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:YES];
//Do not let the user add if the app is in edit mode.
if(editing)
self.navigationItem.rightBarButtonItem.enabled = YES;
else
self.navigationItem.rightBarButtonItem.enabled = YES;
}
,然後鏈接的編輯按鈕setEditing:在工具欄上它並不像顯示在頂部導航的編輯按鈕完成按鈕。它只是保持不變。
但是,您可以刪除某個項目,但無法使用底部按鈕將狀態重置爲正常。
我需要能夠從此導航控制器返回到前一個控制器。但編輯按鈕隱藏後退按鈕。
編輯。
我知道我可以通過代碼添加工具欄。
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithTitle:@"Edit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(setEditing:)];
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:70/255.0f green:155/255.0f blue:19/255.0f alpha:1.0]];
NSArray *arrBtns = [[NSArray alloc]initWithObjects:editButton,anotherButton, nil];
self.toolbarItems = arrBtns;
和
[self.navigationController setToolbarHidden:NO];
甚至
UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 500, 400, 40)];
[self.tableView addSubview:toolBar];
您是否在使用'XIB創建ToolBar? – viral 2013-04-09 10:54:26
我有一個故事板。我在構建器中創建了底部的工具欄和項目。但是你可以使用[self.tableView addSubview:toolBar];設置工具欄並查看我的編輯問題。 – 2013-04-09 11:02:35
得到它的工作? – viral 2013-04-09 11:34:07