在我的应用中,我决定添加一个UIBarButtonItem,用于在视图的右上角撰写电子邮件。所以,我使用了这段代码:
UIBarButtonItem *emailing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(emailIt)];
self.navigationItem.rightBarButtonItem = emailing;
我的应用程序中没有任何变化,没有添加任何按钮。发生了什么事?
答案 0 :(得分:0)
试一试:
CGRect frame = CGRectMake(0, 0, 40, 40);
UIButton *button = [[UIButton alloc] initWithFrame:frame];
[button addTarget:self action:@selector(emailIt) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:title forState:UIControlStateNormal];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = buttonItem;
但是,请确保您使用的是UINavigationController