ios - UIImageView doubles and changes size -


i'm having problem driving me nuts while , can not explain going wrong. have uitableview different views , 3 prototype cells select from. if i'm in group mode show prototype applicationcell form storyboard. first entry looks ok, if have 2 image in second entry doubles , resizes image shown twice - in correct size , again resized cell height (also there exists 1 image in per cell), see image:

enter image description here

here relevant code causes problem:

- (uitableviewcell *)tableview:(uitableview *)table      cellforrowatindexpath:(nsindexpath *)indexpath { if(app == nil && groupedmode) {     uitableviewcell *cell = [table dequeuereusablecellwithidentifier:@"applicationcell"                                                         forindexpath:indexpath];     uilabel *head = (uilabel*)[cell viewwithtag:2];     uilabel *badge = (uilabel*)[cell viewwithtag:3];     uilabel *lastmsg = (uilabel*)[cell viewwithtag:4];     uiimageview *imgview = (uiimageview*)[cell viewwithtag:1];     applicationentity *a = [applications objectatindex:indexpath.row];     head.text = a.name;     badge.text = [nsstring stringwithformat:@"%lu",(unsigned long)a.messages.count];     imagesentity *ie = [imagesentity imagebyappid:a.apptoken imgid:0];     nslog(@"v %li",(long)indexpath.row);     //imgview.contentmode = uiviewcontentmodescaleaspectfit;     imgview.image = ie.computedimage;     cgrect r = imgview.bounds;     nslog(@"bounds %f %f %f %f",r.origin.x,r.origin.y,r.size.width,r.size.height);     r = imgview.frame;     nslog(@"frame %f %f %f %f",r.origin.x,r.origin.y,r.size.width,r.size.height);     imgview.bounds = cgrectmake(0,0,48,48);     imgview.frame = cgrectmake(11,2,48,48);     cell.tag = indexpath.row;     if(cell.gesturerecognizers.count == 0) {         uitapgesturerecognizer * gr = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(applicationclicked:)];         [cell addgesturerecognizer:gr];     }     lastmsg.text = [dateformatter stringfromdate:a.lastmessage];     r = imgview.bounds;     nslog(@"after bounds %f %f %f %f",r.origin.x,r.origin.y,r.size.width,r.size.height);     r = imgview.frame;     nslog(@"after frame %f %f %f %f",r.origin.x,r.origin.y,r.size.width,r.size.height);     return cell; } 

the uiimageview has constraint width = height = 48. tested , found out far:

  1. setting image nil shows no image = no error
  2. not assigning new image not show error.
  3. assigning new image once works.
  4. when happens uiimageview gets new bounds , frame, setting them directly correct values not see log

    v 0 bounds 0.000000 0.000000 48.000000 48.000000 frame 11.000000 2.000000 48.000000 48.000000 after bounds 0.000000 0.000000 48.000000 48.000000 after frame 11.000000 2.000000 48.000000 48.000000 v 1 bounds 0.000000 0.000000 320.000000 110.000000 frame 0.000000 110.000000 320.000000 110.000000 after bounds 0.000000 0.000000 48.000000 48.000000 after frame 11.000000 2.000000 48.000000 48.000000

the 110 height cell height , 320 width. violates constraints. image assign 96x96 pixel shows nice in hdpi displays.

the ordering , images may change need assign right images.

any ideas why happens , how prevent this?

after googling through related answers found @ least solution , idea happened.

table cells have own image already. , code

uiimageview *imgview = (uiimageview*)[cell viewwithtag:1]; 

should have returned uiimageview since 1 set tag 1. apparently not. changing tag 10 in storyboard , code solved it. changing somehow background image of cell.

strange thing other mode has prototype cells image tag 1 , not have kind of problem. still not why happens, @ least know how fix it. hope useful others similar problems.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -