ကျွန်တော် UITableView Delete Tutorial မှာ တုန်းက Edit button နှိပ်လိုက်ရင် Delete လုပ်ဖို့အတွက် ပြောင်းသွားပါတယ်။ Edit ပြန်နှိပ်လိုက်ရင် UITableView က Edit ပုံစုံပြောင်းသွားပေမယ့် Edit ကတော့ Done မပြောင်းသွားပါဘူး။ ပြောင်းသွားအောင် နည်းနည်း ပြင်ဖို့လိုပါတယ်။
//Create Edit Button UIBarButtonItem * editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)];
ကို ကျွန်တော်တို့တွေ အောက်ကလို ပြင်ပါတယ်။
//Create Edit Button UIBarButtonItem * editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(editTable)];
အရင်တုန်းက System Button ကို သုံးထားခဲ့တော့ ကျွန်တော်တို့တွေ စာတွေပြင်လို့ မရပါဘူး။ ဒါကြောင့် စာပြင်လို့ရအောင် style ပြင်လို့ရအောင် initWithTitle ကို သုံးလိုက်တာပါ။ editTable function ကို နည်းနည်းပြင်လိုက်ပါတယ်။
- (void) editTable {
//edit action
[self.tableView setEditing: !self.tableview.editing animated: YES];
//Get editButton
NSArray *toolbar_arr=self.toolbarItems;
UIBarButtonItem *editButton =[toolbar_arr objectAtIndex:0];
if(self.tableview.editing){
editButton.title=@"Done";
editButton.style=UIBarButtonItemStyleDone;
}
else {
editButton.title=@"Edit";
editButton.style=UIBarButtonItemStyleBordered;
}
}
table က edit mode ရောက်နေရင် Done ဆိုတဲ့ button နဲ့ done style ကို ပြောင်းလိုက်ပါတယ်။ နဂို stage ကို ရောက်သွားရင်တော့ Edit ဆိုပြီး ပြန်ပြင်လိုက်ပါတယ်။ လွယ်ပါတယ်ဗျာ။