PDA

View Full Version : Setting navbar title with variable




thomasjt
Jun 22, 2009, 04:28 AM
Hi,

I have a view which is created with details which depend on which button a user clicks. So, say the user clicks a button named 'Tom', I would like the navbar title to be Details of Tom...

I've tried this:

detailView.title = @"Details of %@", whichButton.titleLabel.text;

Where whichButton is the button that the user clicked on. Unfortunately, all this shows me is 'Details of %@' in the navbar title.

Any ideas?



jnic
Jun 22, 2009, 04:56 AM
http://devworld.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/clm/NSString/stringWithFormat:

thomasjt
Jun 22, 2009, 05:33 AM
http://devworld.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/clm/NSString/stringWithFormat:

Wow, that was exactly what I was looking for and was very helpful. Sadly though I suck and (new scenario now) in the situation I am trying to use it this doesn't work:

UIImage *myImage = [[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@", name]]];

Any suggestions? Sorry, I'm very new to Objective-C and the syntax is still really confusing me.

Cheers,

Tom

jnic
Jun 22, 2009, 05:39 AM
imageWithContentsOfFile needs a path:

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImage" ofType:@"png"]];


You might prefer imageNamed if you want to just hand it a string.

thomasjt
Jun 22, 2009, 06:14 AM
Sweet, that was a great help. Thanks very much :)