gpt4 book ai didi

ios - UIAlertView alertViewShouldEnableFirstOtherButton : disables wrong button on iOS7

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:45:03 24 4
gpt4 key购买 nike

我目前正在开发一款需要支持 iOS6 和 iOS7 的应用。

我正在创建这样的警报:

self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil)
message:NSLocalizedString(@"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil), nil] autorelease];

self.newCategoryAlertView.cancelButtonIndex = 1;
self.newCategoryAlertView.tag = alertViewTypeNewCategory;
self.newCategoryAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[self.newCategoryAlertView textFieldAtIndex:0].delegate = self;
[self.newCategoryAlertView textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;
[[self.newCategoryAlertView textFieldAtIndex:0] setReturnKeyType:UIReturnKeyDone];
[[self.newCategoryAlertView textFieldAtIndex:0] setKeyboardAppearance:UIKeyboardAppearanceDefault];
[self.newCategoryAlertView textFieldAtIndex:0].enablesReturnKeyAutomatically = YES;

[self.newCategoryAlertView show];

在委托(delegate)中我实现了以下协议(protocol)方法

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
if(alertView.tag == alertViewTypeNewCategory)
{
UITextField *textField = [alertView textFieldAtIndex:0];
if (!textField.text || [textField.text isEqualToString:@""])
{
return NO;
} else {
return YES;
}
} else {
return YES;
}
}

我的问题是在 iOS6 上运行时左键被禁用(正如预期的那样),但是在 iOS7 上运行时右键被禁用。

我检查了委托(delegate)方法中的 cancelButtonIndex 和 firstOtherButtonIndex 的值,它们在 iOS7 和 iOS6 中是相同的。

有什么提示我做错了吗?或者解决此问题的解决方法?

最佳答案

似乎 iOS 7 已经根据索引更改了按钮的排列顺序。我已经尝试了您的代码并添加了几个按钮来检查排列顺序。

[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil)
message:NSLocalizedString(@"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil),NSLocalizedString(@"Third Button", nil),NSLocalizedString(@"Fourth Button", nil),NSLocalizedString(@"Fifth Button", nil), nil];

对于 iOS 7 中的 UIAlertView

enter image description here

第一个按钮“ButtonOK”位于顶部,第二个按钮位于最后一个位置,其余按钮按升序排列,与以前的 iOS 版本相同。

因此,您可以使用 [[UIDevice currentDevice] systemVersion] 检查 iOS 版本并执行

   if (iOS 7) {
self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil)
message:NSLocalizedString(@"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"ButtonCancel", nil),NSLocalizedString(@"ButtonOK", nil), , nil] autorelease];
}else{
self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil)
message:NSLocalizedString(@"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil), nil] autorelease];
}

关于ios - UIAlertView alertViewShouldEnableFirstOtherButton : disables wrong button on iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19488495/

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