右栏按钮项目不起作用

发布于 2024-12-13 01:18:48 字数 676 浏览 5 评论 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.

如何追踪这个错误?

Actually i am placing a bar button on right side of navigation bar, it's not working. But when i use it as left bar button item, it's working fine. I am using ios5.

It was also not working when i have both button left and right bar button. Then i set the frame for both, then these are working. But when i have only one button on right side, it's not working.

 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.

how to trace out this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凤舞天涯 2024-12-20 01:18:48
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle: @"edit" style: UIBarButtonItemStyleBordered target: self action: @selector(edit_details)];
self.navigationItem.rightBarButtonItem = addButton;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle: @"edit" style: UIBarButtonItemStyleBordered target: self action: @selector(edit_details)];
self.navigationItem.rightBarButtonItem = addButton;
行雁书 2024-12-20 01:18:48
    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];
    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];
我不在是我 2024-12-20 01:18:48

对于 Swift 4.2 代码:

在视图中加载函数

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

函数定义如下:

@objc func edit() {
    // Body definition
}

For Swift 4.2 code:

In the View did load function

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

Function definition goes here:

@objc func edit() {
    // Body definition
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文