ios - Can't refresh a picture inside a UITableView -
i'm trying alter image within tableview. i'm using [mytableview reloaddata];
in method (that firing up) refresh tableview
, can see other elements in tableview refreshing image stays same. missing?
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; uilabel *lblname; uiimageview *checkmark = [[uiimageview alloc] initwithframe:cgrectmake(230, 0, 30, 50)]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; cell.selectionstyle = uitableviewcellselectionstylenone; uiview *backgroundview = [[uiview alloc] initwithframe:cgrectmake(10, 1, 260, 70)]; backgroundview.backgroundcolor = uicolorfromrgb(0x000000, 0.3); backgroundview.userinteractionenabled = yes; checkmark.image = [uiimage imagenamed:@"v.png"]; checkmark.contentmode = uiviewcontentmodecenter; checkmark.backgroundcolor = [uicolor clearcolor]; [backgroundview addsubview:checkmark]; [checkmark release]; [cell.contentview addsubview:backgroundview]; [backgroundview release]; } if (something) { checkmark.image = [uiimage imagenamed:@"halfleft.png"]; nslog(@"something done"); } homecoming cell; }
reloaddata correctly calls method.
your problem simple, pointer on "checkmark" isn't in case cell "reused". :
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; uiview *backgroundview; uiimageview *checkmark; if (cell == nil) { checkmark = [[uiimageview alloc] initwithframe:cgrectmake(230, 0, 30, 50)]; cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; cell.selectionstyle = uitableviewcellselectionstylenone; backgroundview = [[uiview alloc] initwithframe:cgrectmake(10, 1, 260, 70)]; backgroundview.backgroundcolor = uicolorfromrgb(0x000000, 0.3); backgroundview.userinteractionenabled = yes; backgroundview.tag = 555; checkmark.image = [uiimage imagenamed:@"v.png"]; checkmark.contentmode = uiviewcontentmodecenter; checkmark.backgroundcolor = [uicolor clearcolor]; checkmark.tag = 666; [backgroundview addsubview:checkmark]; [checkmark release]; [cell.contentview addsubview:backgroundview]; [backgroundview release]; } else { backgroundview = (uiimageview *)[cell.contentview viewwithtag:555]; checkmark = (uiimageview *)[backgroundview viewwithtag:666]; } if (something) { checkmark.image = [uiimage imagenamed:@"halfleft.png"]; nslog(@"something done"); } homecoming cell; }
but, should more simple (less subviews if possible. or subclass uitableviewcell have pointer on checkmark ;-)
ios objective-c cocoa-touch cocoa
No comments:
Post a Comment