ナビゲーションコントローラーがあります。上部のナビゲーション バーではなく、ツールバーの下部に編集ボタンを配置したいと考えています。
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];