2015-08-15 40 views
0

我在我的單元格中顯示一個圖標,當時收藏按鈕被按下我想要顯示它without reloading the whole tableswift - tableviewcell使用dispatch_async重新加載動畫

於是我就用:

dispatch_async(dispatch_get_main_queue(), {() -> Void in 
self.tableView.reloadData() 
}) 

這立即重新加載表,我希望有一個流暢的動畫效果。 我發現這個,它似乎是爲objectiveC工作的,我該怎麼辦swift

/Put this code where you want to reload your table view 
dispatch_async(dispatch_get_main_queue(), ^{ 
     [UIView transitionWithView:<"TableName"> 
          duration:0.1f 
          options:UIViewAnimationOptionTransitionCrossDissolve 
         animations:^(void) { 
          [<"TableName"> reloadData]; 
         } completion:NULL];  
    }); 

回答

0

看來你可以使用此方法

class func transitionWithView(view: UIView, duration: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) 

這等於你OC使用的代碼。

0

一個簡單的方法來重新加載表的動畫部分使用這樣的事情:

YOUR_TABLE.reloadSections(NSIndexSet(index: 0), withRowAnimation: UITableViewRowAnimation.Automatic) // You can try different UITableViewRowAnimations to see what you like 

編輯:應當指出,這將刷新你的表視圖的第一部分與指定動畫。你可以把它放在你的異步調用中。