How to set an outlet on an UIBarButtonItem. I have programmatically maked this button and now i can not connect the outlet. Is there a code for connecting outlets?
Making the button:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 50, 28);
[button setImage:[UIImage imageNamed:@"donebutton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(releaseKeyboard) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButton1 = [[UIBarButtonItem alloc] init];
[barButton1 setCustomView:button];
self.navigationItem.rightBarButtonItem = barButton1;
Selector:
-(void)releaseKeyboard {
[text resignFirstResponder];
}
Where the problem is:
-(void)keyboardWillHide:(NSNotification *)aNotification {
NSLog(@"Keyboard hide");
barButton.enabled = NO;
}
barButton is not connected to an outlet, because i can’t select anything in the IB.
Yeah, so instead of
use
That’s because you don’t own the reference to
barButton1anymore (you’re in another function — another context), let alonebarButton.