UITableViewCell 单独存在

UITableViewCell present individually

有没有一种方法可以将UITableView中的单元格一个一个地呈现出来?有点像动画,每一行在上一行延迟 0.5 秒后呈现?

我尝试过使用 NSTimer 和带有选择器的延迟方法,但两者都不太奏效。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    cell.userInteractionEnabled = false

      **NSThread.sleepForTimeInterval(0.5)**
       return cell




    **NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "returnCell", userInfo: nil, repeats: false)**

    func returnCell(){
        return cell
    }
}

这是我试过的两种方法

您无法在 cellForRowAtIndexPath 中实现延迟 - 您需要操纵底层 table 数据源,或者至少给人一种这样做的印象。假设您的 table 数据在一个名为 "data" 的数组中,一种方法是 -

var cellCount=0
var timer?

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    if (data.count >0) {
        let self.timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector:"incrementCellCount", userInfo: nil, repeats: true)
    }
}

func incrementCellCount() {
  self.cellCount++

  if (self.cellCount == data.count) {
     self.timer!.invalidate()
     self.timer=nil
  }

  self.tableview.insertRowsAtIndexPaths([NSIndexPath(forRow: self.cellCount-1, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Automatic)
}


func tableView(tableView:UITableView!, numberOfRowsInSection section:Int)->Int
{
   return self.cellCount;
}