0

实际上我在导航栏的右侧放置了一个栏按钮,它不起作用。但是当我将它用作左栏按钮项目时,它工作正常。我正在使用ios5。

当我同时拥有左右栏按钮时,它也不起作用。然后我为两者设置了框架,然后这些都起作用了。但是当我在右侧只有一个按钮时,它不起作用。

 UIButton *but1 = [UIButton buttonWithType:UIButtonTypeCustom];//customising map button.

but1.frame = CGRectMake(270,0,50,40);       

[but1 addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside];//on cilcking an map button clicked method is called.

buttonRight = [[UIBarButtonItem alloc]initWithCustomView:but1];//setting map button on Navigation bar.

self.navigationItem.rightBarButtonItem = buttonRight;//setting button on the Right of navigation bar.

如何追踪这个错误?

4

3 回答 3

2
UIBarButtonItem *addButton=[[UIBarButtonItem alloc]initWithTitle:@"edit" style:UIBarButtonItemStyleBordered target:self action:@selector(edit_details)];
self.navigationItem.rightBarButtonItem=addButton;

检查它会工作

于 2011-10-31T10:48:55.387 回答
1
    UIToolbar* toolbar = [[UIToolbar alloc]
                          initWithFrame:CGRectMake(0, 0, 50, 45)];
    [toolbar setBarStyle: UIBarStyleBlackOpaque];
    // create an array for the buttons
    NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:0];

    // create a standard BarButtonItem
    UIBarButtonItem *SettingsBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_setting.png"] style:UIBarButtonItemStylePlain
                                   target:self
                                   action:@selector(ActionMethod:)];
    [buttons addObject:SettingsBtn];
    [SettingsBtn 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.rightBarButtonItem = [[[UIBarButtonItem alloc]
                                              initWithCustomView:toolbar]autorelease];
    [toolbar release];
于 2011-10-31T12:11:21.963 回答
0

对于Swift 4.2代码:

在视图中做了加载功能

let addButton = UIBarButtonItem(title: "edit", style: .plain, target: self, action: #selector(edit))
 navigationItem.rightBarButtonItem = addButton

函数定义在这里:

@objc func edit() {
    // Body definition
}
于 2019-05-09T07:13:06.293 回答