【发布时间】:2011-06-23 14:23:41
【问题描述】:
我有以下代码用于放置 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 上使用此代码设置触摸事件。
UIImageView *iconView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dashboard-icon.png"]];
UIBarButtonItem *icon = [[UIBarButtonItem alloc] initWithCustomView:iconView];
self.navigationItem.leftBarButtonItem=icon;
[icon release];
[iconView release];
【问题讨论】: