Setting navbar title with variable

Discussion in 'iPhone/iPad Programming' started by thomasjt, Jun 22, 2009.

  1. macrumors newbie

    Joined:
    Apr 16, 2009
    #1
    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:

    Code:
    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?
     
  2. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
  3. thread starter macrumors newbie

    Joined:
    Apr 16, 2009
    #3
    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:
    Code:
    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
     
  4. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #4
    imageWithContentsOfFile needs a path:

    Code:
    [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImage" ofType:@"png"]];
    
    You might prefer imageNamed if you want to just hand it a string.
     
  5. thread starter macrumors newbie

    Joined:
    Apr 16, 2009
    #5
    Sweet, that was a great help. Thanks very much :)
     

Share This Page