2015-04-02 81 views
0

我想傳遞一個值來更新tableview單元格。問題是我無法獲得價值。在實現代碼如下單元代碼是:麻煩傳遞tableview單元格值來刪除單元格

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell; 

    // Gets staff name and puts it in the cell title 
    var sectionTitle:String = aventurasUnicas.objectAtIndex(indexPath.section) as String 
    var sectionStaff:Array = porAventura[sectionTitle]! 
    let staffNic:String = sectionStaff[indexPath.row] as String 
    cell.textLabel?.text = staffNic 

    // Gets the subtitle 
    var subtituloAventura:String = "\(sectionTitle).\(staffNic)" as String 
    var sectionStaff2:Array = subtituloTabla[subtituloAventura]! 
    let staffNic2:String = sectionStaff2[0] as String 
    cell.detailTextLabel?.text = staffNic2 

    cell.accessoryType = UITableViewCellAccessoryType.DetailButton 
    return cell 
    } 

而且我堅持的代碼是:

override func tableView(tableView: UITableView?, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath?) { 
    if (editingStyle == UITableViewCellEditingStyle.Delete) { 
     // I AM STUCK HERE 
    } 
} 

我想要得到的staffNic該計劃的一個部分。感謝您的幫助

回答

0

爲什麼不走這條路 - 你得到它的方式是你設置的方式:

let sectionTitle:String = aventurasUnicas.objectAtIndex(indexPath.section) as String 
let sectionStaff:Array = porAventura[sectionTitle]! 
//the text of the deleted row based on your datasource 
let staffNic = sectionStaff[indexPath.row] as String 

或者把它作爲細胞的文字:

let cell = tableView.cellForRowAtIndexPath(indexPath)! 
let staffNic = cell.textLabel!.text! 
+0

非常感謝。它像這樣工作:let cell = tableView?.cellForRowAtIndexPath(indexPath!) 讓staffNic = cell?.textLabel?.text as String! – 2015-04-02 15:06:25