i have button in tableviewcell , when criteria met, want change button image. have endless scroll tableview.
for example, have 10 cells on first page. first cell meets criteria , button icon change displayed correctly. when scroll 11.the cells icon changed not meets criteria. when scroll down observe 21th, 31th... cells icons changed.
func setupx(){ let authorid = self.yazar?["author_id"].int! let fetchrequest = nsfetchrequest(entityname: "favauthors") let sortdescriptor = nssortdescriptor(key: "authorid", ascending: true) fetchrequest.sortdescriptors = [sortdescriptor] let predicate = nspredicate(format: "authorid == %ld", authorid!) fetchrequest.predicate = predicate let fetchresults = self.context!.executefetchrequest(fetchrequest, error: nil) as? [favauthors] if fetchresults!.count == 0 { }else{ self.followbutton.setimage(uiimage(named: "unfollow button.pdf"), forstate: uicontrolstate.normal) } }
this because cells reused old state. should set image explicitly if not meet criteria.
for example, change:
if fetchresults!.count == 0 { } else { self.followbutton.setimage(uiimage(named: "unfollow button.pdf"), forstate: uicontrolstate.normal) } to:
if fetchresults!.count == 0 { self.followbutton.setimage(uiimage(named: "follow button.pdf"), forstate: uicontrolstate.normal) } else { self.followbutton.setimage(uiimage(named: "unfollow button.pdf"), forstate: uicontrolstate.normal) }
Comments
Post a Comment