문제

I have a navbar with a rightbarbuttonitem of:

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

Though when I compile the app onto a device, the button says edit on it instead of done like it is supposed to. Why is this

I add the button like this:

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

This is the whole code for the view:

-(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.
}

I am not using an xib file just pure code and am presenting to the controller from another

도움이 되었습니까?

해결책

Your issue is that you are using the style of a done button which means it will say edit instead of done as it is basically an edit button which doesn't respond to some selectors edit buttons do. To fix this change your code to this:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top