2015-08-25 25 views
0

我面臨一個問題UITableViewCell.I有使用parse生成的動態數據列表。現在用戶將使用UISwitch檢查/取消選中該單元格。我必須存儲該用戶操作並將其發送到其他viewController。如何獲取特定tableviewcell的ID點擊它上面的uiswitch

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: HotspotCustomCell = tableView.dequeueReusableCellWithIdentifier("htuiViewCell") as! HotspotCustomCell let singleHotspot = hotSpots[indexPath.row] cell.sendCell(singleHotspot.hotspotID, hotspotImg: singleHotspot.hotspotImage, hotspotLbl: singleHotspot.hotspottName) return cell }

func sendCell(hotspotID : String ,hotspotImg : PFFile , hotspotLbl : String) { 
    var tempImage:UIImage! 
    hotspotImg.getDataInBackgroundWithBlock { 
     (imageData: NSData?, error: NSError?) -> Void in 
     if error == nil { 
      if let imageData = imageData { 
       /*Setting up the veriable tempImage.*/ 
       tempImage = UIImage(data:imageData) 
       self.hotspotImage.image = tempImage 
       self.hotspotImage.layer.cornerRadius = self.hotspotImage.frame.size.width/2 
       self.hotspotImage.clipsToBounds = true 
       self.hotspotLabel.text = hotspotLbl 

      } 
     } 
    } 
} 

我怎樣才能選擇這UITableViewCell的項目。 enter image description here

+0

didSelectRowAtIndexPath在您選擇特定單元格時被調用。 – Karlos

+0

但我想在uiSwitch事件上獲取特定的單元格數據。 –

+0

我已經爲此添加了答案。 – Karlos

回答

0

試試這個。

// Declare inside your Class file 
var customIndexPath: NSIndexPath = NSIndexPath() 


//Add this inside didSelectRowAtIndexPath 
customIndexPath = indexPath 
println(customIndexPath) 


//Create an IBAction on switch 
@IBAction func switchOnOFF(sender: AnyObject) { 

    println(customIndexPath) 
    //Use the customIndexPath variable inside your Switch action 
} 
+0

謝謝karios。但是,如果他將選中一個tableviewcell,這個事件將只會得到文件。當他切換不在tableviewcell上時,我需要數據。 –

+0

您可以使用標籤進行切換,併爲兩個切換器創建通用IBAction。根據標籤值,您可以執行相應的操作。 – Karlos

+0

但我不能在標籤中存儲字符串值。 –