右栏按钮不显示 [英] rightbarbuttonitem not displaying

查看:90
本文介绍了右栏按钮不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码用于放置rightbarbuttonitem

I have got following code for putting rightbarbuttonitem

UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightbutton setBackgroundImage:[UIImage imageNamed:@"share-icon.png"] forState:UIControlStateNormal];
    [rightbutton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:rightbutton] autorelease];

但它没有显示任何barbuttonitem。相反,如果我使用下面的代码然后出现barbutton项,但问题是我无法在barbuttonitem上使用此代码设置触摸事件。

But it is not displaying any barbuttonitem. Instead if I use following code then barbutton item appears but problem is i cant set touch event with this code on barbuttonitem.

UIImageView *iconView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dashboard-icon.png"]];
    UIBarButtonItem *icon = [[UIBarButtonItem alloc] initWithCustomView:iconView];
    self.navigationItem.leftBarButtonItem=icon;
    [icon release];
    [iconView release];


推荐答案

您是否尝试为<设置合适的框架code> rightbutton ?例如 rightbutton.frame =(CGRect){CGPointZero,image.size};

另请注意:


在iOS 4及更高版本中,
文件的名称不需要指定
文件扩展名。在iOS 4之前,
您必须指定文件名
extension。

On iOS 4 and later, the name of the file is not required to specify the filename extension. Prior to iOS 4, you must specify the filename extension.

这篇关于右栏按钮不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆