如何在点击其上的uiswitch时获取特定tableviewcell的ID

时间:2015-08-25 13:41:53

标签: swift uitableview

我正面临一个问题UITableViewCell.I有使用parse生成的动态数据列表。现在,用户将使用UISwitch检查/取消选中该单元格。我必须存储该用户操作并将其发送到其他viewController。

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

            }
        }
    }
}

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

1 个答案:

答案 0 :(得分: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
 }