2015-09-06 56 views
1

我有一個TableView,每個單元的附件設置爲「披露指標」,它們正常工作。將「活動指標」添加到TableView並恢復到Swift中的「披露指標」

然後,我決定添加一個活動指標,同時用外部數據源更新每個單元格。要做到這一點,我設置:

cell.accessoryView = UIActivityIndicatorView(activityIndicatorStyle: .Gray) 

當我完成加載外部數據源的數據,我失去了我「披露指標」(在電池的右側的箭頭)。我應該如何恢復「cell.accessoryView」?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let item = items[indexPath.row] 
    var cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell 

    // SET ACTIVITY INDICATOR HERE 
    if cell.accessoryView == nil { 
     let indicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray) 
     cell.accessoryView = indicator 
    } 

    let indicator = cell.accessoryView as! UIActivityIndicatorView 

    // ... some code here ... 

    switch (item.state) { 

     case .New: 
      indicator.startAnimating() 
      self.fetchExternalData(item, indexPath:indexPath) 

     case .Downloaded: 
      indicator.stopAnimating() 

      // I'D LIKE TO RESTORE THE DISCLOSURE INDICATOR HERE 
      cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 
      // cell.accessoryView = ??? 
    } 

    return cell 
} 

回答

2

哎呀,我只是試圖設置「cell.accessoryView =零」和它的工作。我應該想到這一點,然後再發布:-(