UINavigation Help

Discussion in 'iOS Development' started by ZunePod, Apr 5, 2009.

  1. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    UINavigation is reallt clever, but smarter than me.

    Reason I say this is because I want the button the have a pointy bit on the left to signify that the button is taking you back.

    Here's my code:


    UIBarButtonItem *addButton2 = [[[UIBarButtonItem alloc]
    initWithTitle:NSLocalizedString(@"Back", @"")
    style:UIBarButtonItemStyleBordered
    target:self
    action

    Please Register or Log in to view images

    selector(addAction

    Please Register or Log in to view images

    ] autorelease];
    self.navigationItem.leftBarButtonItem = addButton2;
  2. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    Use a UINavigationController. If you push a UIViewController onto it, it automatically adds the back button. To go back programmatically, just pop it off the controller's stack.
  3. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    So I cant just change the style: or target: fields?
  4. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Uhhh... what he's saying is that if you use a UINavigationController to push a view controller, it automatically adds a back button that will return you to the previous page.
  5. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Lemme just say I'm new to coding, I don't exactly grasp what you mean.
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    He's saying that when you push a view controller, the UINavigationController automatically adds the back button. You don't have to do anything at all. There is nothing more to get.


    Or, are we all misunderstanding what you are saying. Do you want to change the title on the back button to "Back" instaed of the title of the previous navigation item?

    If so, then the cheater way to do so would be to change the title of the navigation item to "Back" before you push the next view controller. Don't forget to change it back in viewWillAppear (or wherever is appropriate for your app.

    The right way would be to just create a new UINavigationController category and add in a message that changes the title of the button to whatever NSString. Then, you call that message where appropriate.
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Then search google, read tutorials, and look at some example code. If you're a new person to coding, then you need to understand the language before you can create a program.
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Gojohnnyboi, I think we're all misinderstanding him. Please see my edit above.
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Create UINavigationController-YourAppAdditions.h/m and include that in your app.

    Code:
    @interface UINavigationItem (YourAppAdditions)
    - (void)setBackButtonTitle:(NSString *)title;
    @end
    
    @interface UINavigationItem (YourAppAdditions)
    - (void)setBackButtonTitle:(NSString *)title {
    [INDENT]_backButtonTitle = title;[/INDENT]
    }
    
    In your code
    Code:
    /*--When you set up the UIViewController--*/
    [self.navigationItem setBackButtonTitle:someString];
    
  10. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Arg... then thread starter, could you please be a little more clean on what exactly you wish to do please?

Share This Page