ios - How to Change the image of UIButton when selected which is on tableVIewCell. in Swift 3 -


i implementing dislike button on tableview cell unable change image of button. can me out using swift 3

import uikit  class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate {       @iboutlet weak var tableview: uitableview!     var array: [string] = ["a","b","c","d","e","f"]     override func viewdidload() {         super.viewdidload()      }     func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {         return array.count     }     func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {         let cell: cell_tabletableviewcell = self.tableview.dequeuereusablecell(withidentifier: "cell_tabletableviewcell") uitableviewcell! as! cell_tabletableviewcell!              cell.textlabel?.text = array[indexpath.row]          cell.button_outlet.tag = indexpath.row         cell.button_outlet.addtarget(self, action: "likepressed", for: .touchupinside)          return cell     }  }   func likepressed(sender : uibutton){      sender.isselected = !sender.isselected     } 

while designing custom cell, can add image button different states

  1. default
  2. selected

when add selector button, in selector need change button's selection state

func buttontapped(sender : uibutton){          sender.isselected = !sender.isselected   } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -