本文介绍了向导航栏添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用iPhone SDK将按钮添加到导航栏?
Is it possible to add buttons to the navigation bar using the IPhone SDK?
我已经在导航栏中有2个按钮,分别是leftBarButton和rightBarButton.我还需要2个按钮.如何实现呢?
I already have 2 buttons in the navigation bar as leftBarButton and rightBarButton. I need 2 more buttons. How to implement that?
我没有必要将它们包含在导航栏中.但是由于该应用程序仅包含一个表,所以我认为它不能在其他地方给出.
Its not obligatory that i need them to be included in the navigation bar itself. But since the application contains only a table, i don't think it can be given elsewhere.
推荐答案
您可以使用 UISegmentedControl .检查 UI目录代码示例以在导航栏中检查其用法.
You can use the UISegmentedControl. Check the UICatalog code sample to check its usage in the navigation bar.
以下是一些示例代码:
- (void)viewDidLoad {
[super viewDidLoad];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"up.png"],
[UIImage imageNamed:@"down.png"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 35);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
}
- (void)segmentAction:(id)sender{
if([sender selectedSegmentIndex] == 0){
//do something with segment 1
NSLog(@"Segment 1 preesed");
}else{
//do something with segment 2
NSLog(@"Segment 2 preesed");
}
}
这篇关于向导航栏添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!