- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前正在开发一款需要支持 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
第一个按钮“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/
我想显示带有文本字段的 UIAlertview。如果用户未输入有效的 emai id,则 UIAlertview 的确定按钮将被禁用。 我知道如何显示 UIAlertview 和禁用 UIAlertv
我创建了一个 UIAlertView 子类。它实现了两个 UIAlertViewDelegate 方法:alertView:clickedButtonAtIndex: 在预期时被调用,但是 alert
我有一个带有 UITextField 的 UIAlertView。我已连接 UIAlertView 委托(delegate),并根据 UITextField 中的文本在 alertViewShould
我想显示一条警告消息,我正在使用 iOS SDK 8.1 和 XCode 6.1。我知道 UIAlertView 已被弃用;但是,我的应用程序还必须支持 iOS 7,如果该应用程序在 iOS 7 设备
我目前正在开发一款需要支持 iOS6 和 iOS7 的应用。 我正在创建这样的警报: self.newCategoryAlertView = [[[UIAlertView alloc] initWit
我创建了一个自定义警报 View ,其中包含一个 uitextview subview ,如屏幕截图所示。 alertview with subviewed textview 我想在 TextView
我是一名优秀的程序员,十分优秀!