I am new in programming and i would like to know how i can write NSString with .jpg extension.
I have code where my ViewController has some title and that title i use for NSString. Than i use this string to find image with same name. But i dont know to configure that .jpg extension.
Here is my code:
- (void)viewDidLoad{
[super viewDidLoad];
NSString*imageName = [NSString stringWithFormat:(@"% .jpg", self.title)];
UIImage*image = [UIImage imageNamed:imageName];
[imageView setImage:image];
NSLog(@"%", imageName);
}
Funny is that my NSLog line don't work. Can be the problem in my 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 i push some Cell in my TableViewController push segue is activated and show my second ViewController. This part of code works fine but no NSLog line there even if my viewDidLoad was finished. But when i look on Breakpoint on start viewDidLoad method and on NSLog line it show me
"imageName __NSCFString * @"bread" 0x00000001095515f0
Any help appreciated.
Problem solved. It should be [NSString stringWithFormat:@"%@", self.title] and not [NSString stringWithFormat:(@"%@", self.title)]
NSLog
has the same problem as before, it should beNSLog(@"%@", imageName);
. – ThomasW