ios - UIImage as method return value -
having first dab @ xcode (5.1.1) today.
i trying associate image uiimageview component inside table view cell. direct reference image works, via method call fails:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"personcell" ]; person *person = (self.persons)[indexpath.row]; uilabel *labelname = (uilabel *)[cell viewwithtag:50]; labelname.text = person.name; uiimageview *imageviewpic = (uiimageview *)[cell viewwithtag:51]; // works ok //imageviewpic.image = [uiimage imagenamed:@"ticks"]; // fails (no image in cell) //[imageviewpic setimage:[self imageforscore:person.score]]; imageviewpic.image = [self imageforscore:person.score]; return cell; } -(uiimage *)imageforscore:(int)score { switch (score) { case 1: return [uiimage imagenamed:@"tick"]; case 2: return [uiimage imagenamed:@"cross"]; } return nil; }
i've confirmed valid score of 1 or 2 passed in, image in cell blank (via method call).
what missing?
if you've confirmed score
1
or 2
when method called, there 2 logical sources of problem:
the call
imagenamed
failing. there couple of possible reasons why fail:are
tick
,cross
images included in bundle (under "copy bundle resoures")?or if using
images.xcassets
, images there?either way, confirm capitalization of image name.
you're not providing extension. if loading bundle resources (but not
images.xcassets
), have specify extension if file not png file (e.g. if jpeg file). try specifying extension if not usingimages.xcassets
.
if, on other hand, confirm
imageforscore
returning validuiimage
, might want confirmimageviewpic
correct.it's possible
imageviewpic
, itself,nil
(perhaps subview tag of51
not found).i might suggest confirming other properties of
imageviewpic
(e.g.frame
valid,hidden
flag not turned on, etc.).
Comments
Post a Comment