我正面临一个问题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
}
}
}
}
答案 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
}