开发者

Need 2 UIBarButtonItems where back button is located

I have a typical UINavigationController scheme but I have many many views which can mean you can end up having quite a few views stacked on top of each other. I want to provide a home button and originally I was going to put that on the right hand side of the navigation bar; however, I have a search bar there and another button so I am hoping to put it next to the back button.

In ascii art:

< Back |  |Home|                Title              |Browse| [Search Bar]

Now I tried to set the backButtonItem of the previous view controller using the following:

        UIToolbar* toolbar = [[UIToolbar alloc]
                  开发者_开发知识库        initWithFrame:CGRectMake(0, 0, 100, 45)];
    [toolbar setBarStyle: UIBarStyleBlackOpaque];

    // create an array for the buttons
    NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

    UIBarButtonItem *back = [[UIBarButtonItem alloc] init];
    back.title = @"Back";

    // create a standard save button
    [buttons addObject:back];
    [back release];

    // create a spacer between the buttons
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
                               initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                               target:nil
                               action:nil];
    [buttons addObject:spacer];
    [spacer release];

    UIBarButtonItem *homeButton = [[UIBarButtonItem alloc]
                                   initWithImage:[UIImage imageNamed:@"home32.png"] 
                                   style:UIBarButtonItemStylePlain 
                                   target:self 
                                   action:@selector(onHomeButton:)];
    homeButton.style = UIBarButtonItemStyleBordered;
    [buttons addObject:homeButton];
    [homeButton release];

    // put the buttons in the toolbar and release them
    [toolbar setItems:buttons animated:NO];
    [buttons release];

    // place the toolbar into the navigation bar
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
                                             initWithCustomView:toolbar];
    [toolbar release]; 

but that doesn't seem to replace the standard back button. If I just try one UIBarButtonItem and set the backButton, that works.

Now the other approach I tried is that on the View that is pushed on the stack, to set the leftBarButtonItem but I can't seem to find a way to create a back button that has the pointy shape to the left.

Any suggestions?


can you try

self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]
                                             initWithCustomView:toolbar];

good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜