I have a strange problem in tableView
Custom cell
. for like Image action I write these code in Custom cell
called FeedViewCell>
Take one array
let arr : NSMutableArray = NSMutableArray()
And in tableview take button instead of image and set unlike image in button and set your images instead of my images
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let btn = cell.viewWithTag(10) as! UIButton
btn.addTarget(self, action: #selector(ViewController.connected(_:)), forControlEvents: .TouchUpInside)
return cell
}
func connected(sender: UIButton){
let buttonposition = sender.convertPoint(CGPointZero, toView: self.tblview)
let index = self.tblview.indexPathForRowAtPoint(buttonposition)
if !arr.containsObject((index?.row)!) {
arr.addObject((index?.row)!)
sender.setImage(UIImage(named: "ic_check.png"), forState: .Normal)
}else
{
arr.removeObject((index?.row)!)
sender.setImage(UIImage(named: "ic_uncheck.png"), forState: .Normal)
}
}