在导航栏中显示多个按钮

KUM*_*R.A -3 iphone ios

在我的应用程序中,我想显示2个按钮(每个按钮具有不同的动作)代替导航栏的右栏按钮.我该怎么做?

Nit*_*hel 5

这是一个你想要它的工作和帮助的代码

将下面的代码放入

 -(void)viewWillAppear:(BOOL)animated 
  {
     UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
     tools.tintColor = [UIColor clearColor];

     [tools setBarStyle:UIBarStyleBlackTranslucent];
     tools.barStyle = -1; // clear background
     NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];

    // Create a standard refresh button.

     UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
     [button setImage:[UIImage imageNamed:@"Settings.png"] forState:UIControlStateNormal];
     [button addTarget:self action:@selector(resetpass) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 30,30 )];
bi = [[UIBarButtonItem alloc] initWithCustomView:button];

[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
bi.width = 2.0f;
[buttons addObject:bi];
[bi release];

// Add profile button.
bi = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createnewFolders)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
[buttons release];
twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];

self.navigationItem.leftBarButtonItem = twoButtons;

[twoButtons release];
 }
Run Code Online (Sandbox Code Playgroud)

谢谢