iphone - UIImageView not showing up in custom UITableViewCell -
here code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"convorecell"; convorecell * cell = (convorecell *) [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"convorecell" owner:nil options:nil]; (id currentobject in toplevelobjects){ if ([currentobject iskindofclass:[uitableviewcell class]]){ cell = (convorecell *) currentobject; break; } } } nsmutabledictionary *cellvalue = [results objectatindex:indexpath.row]; nsstring *picurl = [[cellvalue objectforkey:@"creator"] objectforkey:@"img"]; if ([picurl isequaltostring:@"https://secure.gravatar.com/avatar/1f043010eb1652b3fab3678167dc0487/?default=https%3a%2f%2fconvore.com%2fmedia%2fimages%2feric.png&s=80"]) picurl = @"https://convore.com/media/images/eric.png"; if ((picurl != (nsstring *) [nsnull null]) && (picurl.length !=0)) { nslog(@"%@", picurl); nsdata *imgdata = [[[nsdata datawithcontentsofurl: [nsurl urlwithstring: picurl]] autorelease] retain]; [cell.pic initwithimage:[[uiimage alloc] initwithdata:imgdata]]; } else { cell.pic = nil; } //nslog(@"name : %@", [cellvalue objectforkey:@"name"]); cell.title.text = [cellvalue objectforkey:@"name"]; cell.info.text = (@"created by: %@", [[cellvalue objectforkey:@"creator"] objectforkey:@"name"]); cell.accessorytype = uitableviewcellaccessorydisclosureindicator; // configure cell... return cell;
}
for reason image not showing up. doing wrong here? url of image valid, checked.
also don't want have accessory view on tableviewcell, did specify no in ib, still shows up... set accessory attribute none already
you have issues in code.
nsdata *imgdata = [[[nsdata datawithcontentsofurl: [nsurl urlwithstring: picurl]] autorelease] retain];
the former not real issue (maybe coincidence?!), it's ugly , confusing. rid of autorelease , retain. object datawithcontentsofurl: autoreleased.
[cell.pic initwithimage:[[uiimage alloc] initwithdata:imgdata]];
and real issue might this. know should call init 1 time; after you've allocated object.
so if cell.pic uiimageview try change code this:
cell.pic.image = [[[uiimage alloc] initwithdata:imgdata] autorelease];
once see images should change code saves images in data use populate cell. downloading image every time cell appears. that's shouldn't do. beyond question.
edit:
also don't want have accessory view on tableviewcell, did specify no in ib, still shows up... i set accessory attribute none already
you do? can see line of code:
cell.accessorytype = uitableviewcellaccessorydisclosureindicator;
Comments
Post a Comment