2011年9月3日 星期六

Lala's Program Note 實作記錄: 8. 調整: 刪除 NoteBook 的按鈕機制

since: 2011/09/03
update: 2011/09/03


A. 說明:
   1. 原本的刪除功能是在 EditDone 之間切換, 易讓使用者混淆.


  2. 因此改成如下的顯示方式:


B. 作法:
   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.mviewDidLoad 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
    ....
    
}

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。