Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更新代码,应用程序保持不变_Ios_Uibarbuttonitem - Fatal编程技术网

Ios 更新代码,应用程序保持不变

Ios 更新代码,应用程序保持不变,ios,uibarbuttonitem,Ios,Uibarbuttonitem,在我的应用程序中,我决定在视图的右上角添加一个用于撰写电子邮件的UIBarButtonItem。因此,我使用了以下代码: UIBarButtonItem *emailing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(emailIt)]; self.navigationItem.rightBarButtonI

在我的应用程序中,我决定在视图的右上角添加一个用于撰写电子邮件的UIBarButtonItem。因此,我使用了以下代码:

UIBarButtonItem *emailing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(emailIt)];
    self.navigationItem.rightBarButtonItem = emailing;
我的应用程序中完全没有任何更改,没有添加任何按钮。发生了什么事?

试试看:

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

视图控制器是否在UINavigationController中?如果OP的代码不起作用,这也不会起作用。不需要创建自定义按钮来解决此问题。