update: 2011/09/03
A. 說明:
1. 原本的刪除功能是在 Edit 與 Done 之間切換, 易讓使用者混淆.
1. 在 NoteBookViewController.h 宣告一個用來切換垃圾桶與 Done 狀態的 method.
- (void)toggleDelete;
2. 在 NoteBookViewController.m 定義此 method 的內容.
- (void)toggleDelete {
/* 切換編輯狀態 */
[self setEditing:!self.editing animated:YES];
/* 正在編輯(刪除)中 */
if (self.editing) {
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(toggleDelete)];
self.navigationItem.leftBarButtonItem = doneButton;
[doneButton release];
}
/* 尚未編輯(刪除) */
else {
UIBarButtonItem *trashButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self action:@selector(toggleDelete)];
self.navigationItem.leftBarButtonItem = trashButton;
[trashButton release];
}
}
3. 修改 NoteBookViewController.m 內 viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
// 實際上是進入刪除的功能
//@deleteButton
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(toggleDelete)];
self.navigationItem.leftBarButtonItem = deleteButton;
[deleteButton release];
//@addButton
....
}
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。