iOS swift UIImageView change image in tableView cell

后端 未结 3 595
南旧
南旧 2021-01-16 22:21

I have a strange problem in tableView Custom cell. for like Image action I write these code in Custom cell called FeedViewCell

3条回答
  •  余生分开走
    2021-01-16 22:47

    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)
            }
    
        }
    

提交回复
热议问题