2014-11-03 111 views
0

至於iOS 8和Xcode 6,我能夠使用UITableViewController,非常類似Apple的設置來配置我的應用程序。在從一張表回到調用表中,我會重新加載調用表以更新單元格中的數據,重新選擇調用行,然後讓視圖顯示動畫以清除選擇。重新加載表格和清除單元格行選擇

這裏是在viewWillAppear中方法的代碼,我一直在使用:

[self.tableView reloadData]; 
[self.tableView selectRowAtIndexPath:lastselected animated:YES scrollPosition:UITableViewScrollPositionNone]; 
[super viewWillAppear:animated]; 

當單元格數據更新時,選擇行的不錯的慢消失/電池不會發生。它被立即有效清除。我嘗試過所有我能想到的事情,但無法實現這一目標。請幫助...

什麼改變了,我怎麼能得到這個很好的轉換回來?

謝謝。

回答

0

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]; 
} 
+0

謝謝。這實際上並沒有像你計劃的那樣有幫助,但是我可以通過這樣做來實現它: - (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

+0

在您的評論代碼中,您正在執行兩次'selectRowAtIndexPath'調用。你不需要第一個'selectRowAtIndexPath'只有執行選擇器中的延遲。如果我的viewDidAppear版本不起作用,我會感到非常驚訝,儘管我很高興在這種情況下的延遲解決了你的問題......正如我所說,儘管如此,技術上它是一個不確定的數量在「確實出現」之前的時間。 – Magoo 2014-11-04 22:47:25

+0

良好的catch..it其實是一個deselectRowAtIndexPath而不是另一個選擇。複製/粘貼錯誤。 – SteveM 2014-11-05 19:40:01

相關問題