如何在 UIBarButtonItem 上设置插座。我以编程方式制作了这个按钮,现在我无法连接插座。有连接插座的代码吗?
制作按钮:
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;
选择器:
-(void)releaseKeyboard {
[text resignFirstResponder];
}
问题出在哪里:
-(void)keyboardWillHide:(NSNotification *)aNotification {
NSLog(@"Keyboard hide");
barButton.enabled = NO;
}
barButton 未连接到插座,因为我无法在 IB 中选择任何内容。