ios - Flickering Section Headers when it refreshes? -
i have a series of uitableviewcells
update every second or so.
first attempt: in order perform such update, call self.tableview.reloaddata()
reload cell contents.
second attempt: have tried refreshing sections uitableviewanimation.none
makes section header disappear , reappear every second.
in first attempt, "flickering" effect because views being refreshed. want flickering effect goes away. in second attempt, said above, section header disappear , reappear every second.
in code, want update headerview.headertimeleft.text
label.
here attempts:
override func viewdidappear(animated: bool) { super.viewdidappear(animated) self.refreshtimer = nstimer.scheduledtimerwithtimeinterval(1.0, target: self, selector: "refreshview:", userinfo: nil, repeats: true) } func refreshview(timer: nstimer){ //attempt 2 var visiblerows:nsarray = self.tableview.indexpathsforvisiblerows()! var sections = nsmutableindexset() indexpath in visiblerows{ sections.addindex(indexpath.section) } //attempt 1 reload data //self.tableview.reloaddata() //attempt 2 reload sections self.tableview.reloadsections(sections, withrowanimation: uitableviewrowanimation.none) } func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? { //show section header cell name of event creator var cellidentifier = "sectionheadercell" var headerview = tableview.dequeuereusablecellwithidentifier(cellidentifier) as! sectionheadercell headerview.backgroundcolor = uicolor.whitecolor() headerview.creator.text = self.events[section].eventcreator() var fromdate = self.events[section].fromdate()! + " " + self.events[section].fromtime()! var dateformatter = nsdateformatter() dateformatter.dateformat = "mm/dd/yy hh:mm z" var eventstartdate = dateformatter.datefromstring(fromdate)?.timeintervalsince1970 var timeuntilend = eventstartdate! - nsdate().timeintervalsince1970 //display time left var seconds = timeuntilend % 60 var minutes = (timeuntilend / 60) % 60 var hours = timeuntilend / 3600 headerview.headertimeleft.text = nsstring(format: "%dh %dm %ds", int(hours), int(minutes), int(seconds)) string return headerview }
you're trying update label correct? shouldn't need redraw entire header view. if change label text , possibly call setneedsdisplay on label should take care of itself.
Comments
Post a Comment