iOS UITableView : clear section button -


i need add clear button in table view section header. same 1 in notification center. when user clicks it, 'x' change 'clear'. if s/he clicks again, app perform action. click outside button, 'clear' 'x'

how can make this? in advance

enter image description here

unfortunately not come out of box. have create own custom section header view. custom header view contains uilabel on left side. on right side put uibutton has title "x". when user taps on button, change title "clear" , state .selected. clear table view section when button tapped , state .selected:

func setupbutton() {     let button = uibutton()     button.settitle("x", forstate: .normal)     button.addtarget(self, action: selector("didpressbutton:"), forcontrolevents: .touchupinside)     addsubview(button) }  func didpressbutton(button: uibutton) {     if button.selected {         // clear table view section     }     button.settitle("clear", forstate: .normal)     button.selected = true } 

to put button in unselected state add background uiview section header view , add uitapgesturerecognizer it:

func setupbackground() {     let background = uiview()     let recognizer = uitapgesturerecognizer(target: self, action: selector("didtapoutside:"))     background.addgesturerecognizer(recognizer)     insertsubview(background, belowsubview: button) }  func didtapoutside(recognizer: uitapgesturerecognizer) {     button.selected = false     button.settitle("x", forstate: .normal) }  

to use custom section header in table view implement following uitableviewdelegate method:

func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? {      // create custom section header , return    } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -