ios - UITableView change image on cell select and reset others -
i'd change uiimage
inside uitableviewcell
when user selects row. thats dificult. can in didselectrowatindex
fine. however, , heres problem, want other cells (each cell
has standard image) have standard image again. (if cells have standard image again, selected image should "marked" (meaning non-marked image replaced marked image, have code for)
see checkbox
know html
.
here attempt:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview cellforrowatindexpath:indexpath]; [tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:yes]; //little flashing animation [tableview deselectrowatindexpath:indexpath animated:yes]; [uiview animatewithduration:2.0f animations:^{ } completion:^(bool finished) { ; }]; //mark selected cell uitableviewcell *cell = [tableview cellforrowatindexpath:indexpath]; alog(@"%i", cell.imageview.tag); alog(@"%i", [[[tableview cellforrowatindexpath:indexpath] imageview] tag]); uiimageview *iconimgview = (uiimageview *)[[tableview cellforrowatindexpath:indexpath] viewwithtag:tag_imagemarkercell]; [iconimgview setimage:[uiimage imagenamed:@"circle-answer-marked.png"]]; //.. }
the uiimageview
defined here:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { //add cell once, not everytime cell displayed! (everyhing goes in here) cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; [[cell textlabel] setnumberoflines:0]; // unlimited number of lines [[cell textlabel] setlinebreakmode:nslinebreakbywordwrapping]; [[cell textlabel] setfont:[uifont fontwithname:@"ptsans-regular" size:33 / 2]]; [[cell textlabel] settextcolor:[self colorfromhexstring:color_default_text_color]]; cell.indentationlevel = cell.indentationlevel + 2; // //marker image imgcell_marker = [[uiimageview alloc]initwithframe:cgrectmake(10, 22, 20, 20)]; imgcell_marker.image=[uiimage imagenamed:@"circle-answer.png"]; imgcell_marker.tag = tag_imagemarkercell; alog(@"%@", imgcell_marker); [cell.contentview addsubview:imgcell_marker]; } //.. return cell; }
odd thing is, uiimageview
s have predefined tag
if want hands on in didselectrowatindexpath
"0". (the default value of tag
)
thanks in advance.
you have issues on number of fronts.
first, information determines image should displayed should part of model. so, when row selected, set flag in model item tagged. @ same time, find other items tagged , untag them. now, reload rows have changed. in cellforrowatindexpath
, update requested cells set standard or alternative image based on tag info model.
second, use of tag
- getting mixed between imgcell_marker
, imageview
. when do:
alog(@"%i", [[[tableview cellforrowatindexpath:indexpath] imageview] tag]);
you querying default imageview
, tag
zero. should using viewwithtag:tag_imagemarkercell
find actual image view want.
Comments
Post a Comment