Adding a UIBarButtonItem to a programattically allocated UINavigationBar
- by iamdadude
I have a cameraoverlayview that allocates a UINavigationBar to the top of the screen like this -
CGRect navbarFrame = CGRectMake(0, 0, 320, 44);
navigationBar = [[UINavigationBar alloc] initWithFrame:navbarFrame];
navigationBar.delegate = self;
Now I want to add a UIBarButtonItem as the left button to the navigation bar, but the standard navigationbar.leftitem doesn't work. So I tried doing this -
closebutton = [[UIBarButtonItem alloc] initWithTitle:closebuttontext style:UIBarButtonItemStylePlain target:self action:@selector(close)];
navigationBar.topItem.leftBarButtonItem = closebutton;
But it doesn't work either. Can anyone point me in the right direction? As far as the navigation bar loading up correctly in the cameraoverlayview, it works 100%.