xcode - How to write NSString with .jpg for all strings? -
i new in programming , know how can write nsstring .jpg extension.
i have code viewcontroller has title , title use nsstring. use string find image same name. dont know configure .jpg extension.
here code:
- (void)viewdidload{ [super viewdidload]; nsstring*imagename = [nsstring stringwithformat:(@"% .jpg", self.title)]; uiimage*image = [uiimage imagenamed:imagename]; [imageview setimage:image]; nslog(@"%", imagename); }
funny nslog line don't work. can problem in prepareforsegue method?:
-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if ([segue.identifier isequaltostring:@"cell segue"]) { imageshowingviewcontroller*ivc = segue.destinationviewcontroller; ivc.title = [self.objects objectatindex:(self.tableview.indexpathforselectedrow.row)]; } }
when push cell in tableviewcontroller push segue activated , show second viewcontroller. part of code works fine no nslog line there if viewdidload finished. when on breakpoint on start viewdidload method , on nslog line show me
"imagename __nscfstring * @"bread" 0x00000001095515f0
any appreciated.
problem solved. should [nsstring stringwithformat:@"%@", self.title] , not [nsstring stringwithformat:(@"%@", self.title)]
use
nsstring *imagename = [nsstring stringwithformat:@"%@.jpg", self.title]; uiimage*image = [uiimage imagenamed:imagename]; [_image setimage:image];
stringwithformat:
should used instead of stringwithstring:
. also, parenthesis shouldn't used in expression.
also, not clear [image setimage:image];
supposed do. first image
image view? i've updated answer distinct loaded image, you'll need determine value should be.
Comments
Post a Comment