Question

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

Was it helpful?

Solution

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)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top