我在編程iOS時遇到了一個問題:當我嘗試爲我的tableView製作自定義編輯按鈕時,我無法將其設置爲動畫。下面是我的初始化實現代碼如下:setEditing:animated:缺少動畫?
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
.......
self.view = myTableView;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(setEditing:animated:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}
然而,當我用self.editButtonItem而不是我的Add按鈕,編輯模式是動畫。這是我的setEditing:animated:方法。我可以讓我的tableview進入編輯模式,插入按鈕立即出現在左邊。我試過[myTableView reloadRowsAtIndexPaths:[myTableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];
但它在iOS 4.3上沒有幫助。
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
if(self.editing){
[super setEditing:NO animated:YES];
[myTableView reloadRowsAtIndexPaths:[myTableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];
[myTableView reloadData];
self.navigationItem.title = [selectedCellItem valueForKey:@"name"];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(setEditing:animated:)];
self.navigationItem.rightBarButtonItem = addButton;
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
[addButton release];
}
else {
[super setEditing:YES animated:YES];
[myTableView reloadRowsAtIndexPaths:[myTableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];
self.navigationItem.title = @"Add to Favourites";
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(setEditing:animated:)];
self.navigationItem.rightBarButtonItem = doneButton;
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
[doneButton release];
[myTableView reloadData];
}
}
對不起,我已經試過了,但還是沒有用=( – Yangrui
嘗試取出reloadRows ..電話,它們是什麼,因爲他們會立即更換電池,因此可以發生在你的動畫完成 – jrturton
是的,我已經刪除了我行應修改我的[超級setEditing:NO動畫:是];?。??我只是想在我的導航欄上製作一個自定義編輯按鈕或者我可以在哪裏找到一些易於理解的代碼? – Yangrui