gpt4 book ai didi

iphone - 当键盘滑入时如何禁用导航栏中的 'Done' 按钮?

转载 作者:行者123 更新时间:2023-12-03 20:57:21 26 4
gpt4 key购买 nike

我相信我无法禁用它,因为我无法以编程方式访问该 UIBarButttonItem
(使用 viewWithTag 或 rightBarButtonItem)。

有什么建议(除了添加不带 IB 的接口(interface)之外)吗?
作为测试,我还尝试以编程方式添加按钮(在导航栏的左侧),但它没有显示在导航栏中。

相关代码(在MyEditorViewControler.m中):

    - (void)textFieldDidBeginEditing:(UITextField *)sender { //successfully executes when keyboard slides in

UINavigationItem *item = self.navigationItem; //item = 0x6420e0 OK. (value at debugger breakpoints)
UIBarButtonItem *doneButton4 = (UIBarButtonItem *) [self.view viewWithTag:44]; //doneButton4 = 0x0, not OK.
doneButton4.enabled = NO;
}
- (void)textFieldDidEndEditing:(UITextField *)sender { //successfully executes when keyboard slides out.
...
UIButton* doneButton = (UIButton *)[self.view viewWithTag:44]; //Attempt to re-enable button.
doneButton.enabled = YES;
}
- (void)viewDidLoad { //Attempt to programmatically add a *left* button to the nav bar. Result: Button does not display in nav bar.
....
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
[leftBarButtonItem release];
}

详情
我认为这是一种常见情况,因为“完成”按钮:
a) 是从 IB 库添加到导航栏的 UIBarButttonItem,该导航栏位于具有一些 UITextField 的 ScrollView 中。
b)按预期运行(保存用户输入的数据等),
除了键盘出现时不会被禁用。
c) IB > 检查器 > 栏按钮项目属性显示:
标识符 = 完成
标签 = 44
类 = UIBarButtonItem

最佳答案

你应该只是使用

UIBarButtonItem *doneButton = self.navigationItem.leftBarButtonItem; 
doneButton.enabled = YES;

//Both of these should work, you shouldn't need any type of IBOutlets for this

UINavigationItem *item = self.navigationItem;
UIBarButtonItem *doneButton = item.leftBarButtonItem;

关于iphone - 当键盘滑入时如何禁用导航栏中的 'Done' 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4136027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com