我有一个带有rightbarbuttonitem的导航栏:

[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];


虽然当我将应用程序编译到设备上时,该按钮上显示的是对其进行编辑,而不是按应有的方式进行。为什么是这样

我添加这样的按钮:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];


这是该视图的全部代码:

-(void) done {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Edit";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];
    // Do any additional setup after loading the view.
}


我不只是使用纯代码的xib文件,而是从另一个控制器呈现给我

最佳答案

您的问题是您使用的是完成按钮的样式,这意味着它会说编辑而不是完成,因为它基本上是一个编辑按钮,对某些选择器的编辑按钮没有反应。要解决此问题,请将您的代码更改为此:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];

08-15 20:36
查看更多