viewWillAppear
在您的視圖在屏幕上之前調用。因此,如果從該方法內部啓動,您將無法正常使用任何動畫。使用viewDidAppear
代替,您應該在轉場時看到更可靠的動畫..如果感覺速度太快,可能會延遲使用performSelector
。
就個人而言,我會在這種情況下首先打電話[super viewDidAppear:animated];
。我看不出它會低於其他代碼行的原因。
也只是所以我是100%的透明...... viewWillAppear
顯然是OK的重裝的tableView所以讓我們做到這一點...
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView selectRowAtIndexPath:lastSelected animated:YES scrollPosition:UITableViewScrollPositionNone];
}
或者與viewDidAppear的執行選擇延遲...
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:@selector(animateCellSelectionAtIndexPath:) withObject:lastSelected afterDelay:0.2f];
}
-(void)animateCellSelectionAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}
謝謝。這實際上並沒有像你計劃的那樣有幫助,但是我可以通過這樣做來實現它: - (void)viewWillAppear:(BOOL)animated {self.tableView reloadData]; [self.tableView selectRowAtIndexPath:lastselected animated:YES scrollPosition:UITableViewScrollPositionNone]; [self performSelector:@selector(animateCellSelectionAtIndexPath :) withObject:lastselected afterDelay:0.05f]; } - (無效)animateCellSelectionAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath動畫:YES]; } – SteveM 2014-11-04 14:14:43
在您的評論代碼中,您正在執行兩次'selectRowAtIndexPath'調用。你不需要第一個'selectRowAtIndexPath'只有執行選擇器中的延遲。如果我的viewDidAppear版本不起作用,我會感到非常驚訝,儘管我很高興在這種情況下的延遲解決了你的問題......正如我所說,儘管如此,技術上它是一個不確定的數量在「確實出現」之前的時間。 – Magoo 2014-11-04 22:47:25
良好的catch..it其實是一個deselectRowAtIndexPath而不是另一個選擇。複製/粘貼錯誤。 – SteveM 2014-11-05 19:40:01