我有一个iPad应用程序.我正在创建一个UIAlertController并添加一个文本字段.它崩溃了.它只在我添加文本字段时崩溃.
let alert = UIAlertController(title: "Enter Name", message:nil, preferredStyle: UIAlertControllerStyle.Alert);
alert.addTextFieldWithConfigurationHandler { (textfield:UITextField!) -> Void in
textfield.placeholder = "Sexy time";
}
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: {(action:UIAlertAction!) -> Void in
//Some action here
}));
self.presentViewController(alert, animated: true, completion: nil);
Run Code Online (Sandbox Code Playgroud)
我得到一个有趣的崩溃告诉我,约束搞砸了.此代码在<8.3中正常工作,没有任何警告.即使在一个没有任何内容的干净项目中,但是这个代码崩溃了 - 该项目需要成为iPad上的splitview项目.
这是完整的堆栈跟踪加上奇怪的约束警告,只有在尝试将文本字段添加到alertController后才会出现.
2015-04-10 15:25:07.155 Observation[18235:281813] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fb66cf9dfc0 UITableView:0x7fb66b855000.left == UIView:0x7fb66fae68e0.left>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的UIAlertViews更改为UIAlertControllers.我为它设置了这个动作:
UIAlertAction *undoStopAction = [UIAlertAction actionWithTitle:@"Undo Stop"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self undoStop];
}];
Run Code Online (Sandbox Code Playgroud)
但是,处理程序在操作被点击后大约一秒钟才会运行.有什么方法可以加快速度吗?
在iOS 8及更低版本中显示UIActionSheet何时呈现键盘将在键盘上显示操作表.对于iOS 9,情况已不再如此.
在我的应用程序中,我们有一个聊天功能,并希望该节目通过键盘进行操作.我们过去常常使用UIActionSheet哪种工作正常,直到iOS 8.在iOS 9中,操作表存在于键盘后面.我都试过UIActionSheet和UIAlertController.
我已经尝试将动作表放在它自己的窗口中并覆盖canBecomeFirstResponder,这使得键盘消失了.
UAlertView在iOS 9及更高版本中已弃用.什么是另类?
UIAlertView *new = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Your InApp Purchases were successfully restored" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[new show];
Run Code Online (Sandbox Code Playgroud) 我曾经在我的应用程序中长时间使用"请稍候"对话框.使用UIActivityIndicatorView和添加它是非常简单的事情UIAlertView.
但是iOS8推出了UIAlertController.是否可以添加任何东西以产生类似的效果?还有其他方法可以用iOS8做这样的事情吗?
我搜索了很多网站,但仍然不知道如何使用新的API.
我会很感激任何答案 - 链接到libs,教程等,这可能会有所帮助.
问候,
Mateusz
我正在将我的应用程序移植到iOS 8.0,并注意到UIAlertView已被弃用.
所以我改变了使用UIAlertController的东西.在大多数情况下都有效.
除了,当我的应用程序打开时,它会进行多次检查以向用户报告各种状态...
例如.."警告,你没有设置X并且在完成项目之前需要做Y"和"警告,你正在使用测试版并且不依赖于结果"等......(这些只是示例!)
在UIAlertView下,我会(比如说)同时获得两个警告框,用户必须点击两次才能解除两个...但它们都出现了.
在UIAlertController下面,使用下面的代码来显示"常规"警报,我只收到一条警报消息以及一条控制台消息:
警告:尝试在TestViewController上呈现UIAlertController:0x13f667bb0:0x13f63cb40已经呈现UIAlertController:0x13f54edf0
所以,虽然上面可能不是一个很好的例子,但我想有时可能需要在操作应用程序时因"事件"而提出多个全局警报.在旧的UIAlertView下,它们会出现,但似乎它们不会在UIAlertController下.
任何人都可以建议如何使用UIAlertController实现这一目标?
谢谢
+(void)presentAlert:(NSString*)alertMessage withTitle:(NSString*)title
{
UIAlertController *alertView = [UIAlertController
alertControllerWithTitle:title
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:kOkButtonTitle
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Do some thing here
[alertView dismissViewControllerAnimated:YES completion:nil];
}];
[alertView addAction:ok];
UIViewController *rootViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
[rootViewController presentViewController:alertView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
编辑:我注意到在iOS8上,连续呈现两个AlertViews,它们"排队"并按顺序出现,而在iOS7中,它们同时出现.似乎Apple已经改变了UIAlertView来排队多个实例.是否有办法使用UIAlertController执行此操作而不继续使用(已弃用但已修改)UIAlertView ???
我正在尝试使用iOS 8 UIAlertController代替我UIAlertView过去使用过的地方.我希望用户能够在此警报中输入文本并点击"确定"处理文本或"取消"取消.
这是基本代码:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Value" message:@"Enter your new value."];
[alert addTextFieldWithConfigurationHandler:nil];
[alert addAction: [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *textField = alert.textFields[0];
NSLog(@"text was %@", textField.text);
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"Cancel pressed");
}]];
[presentingVC presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
随着老UIAlertView,我会用它标记alertViewStyle的UIAlertViewStylePlainTextInput.然后,如果用户在输入文本后点击其键盘上的"返回"按钮,willDismissWithButtonIndex:则会调用UIAlertViewDelegate方法buttonIndex(取决于在其中指定的按钮UIAlertView).
在新的情况下UIAlertController,如果用户点击"确定"或"取消"按钮,则按预期执行相应的操作; 但如果用户只是按下键盘上的"返回"键,它只是隐藏了键盘,但警报仍保留在屏幕上,并且不执行任何操作.
我已经考虑过配置文本字段来设置UITextFieldDelegateto self,然后可能重写textFieldDidReturn:方法,但我也不知道是否有办法以UIAlertController编程方式调用其中一个动作.无论如何,这听起来有点混乱/ hacky.我错过了一些明显的东西吗
我创建了一个带有a的注册表单,UIAlertController并使用该方法addTextFieldWithConfigurationHandler添加文本字段.但是有一点问题.
当表单出现时,键盘和模态会以平滑的动画显示.关闭表单时,模态首先消失,然后键盘消失.这使键盘突然下降.
如何使模态和键盘优雅地消失?
lazy var alertController: UIAlertController = { [weak self] in
let alert = UIAlertController(title: "Alert", message: "This is a demo alert", preferredStyle: .Alert)
alert.addTextFieldWithConfigurationHandler { textField in
textField.delegate = self
}
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
return alert
}()
@IBAction func alert() {
presentViewController(alertController, animated: true, completion: nil)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
alertController.dismissViewControllerAnimated(true, completion: nil)
return true
}
Run Code Online (Sandbox Code Playgroud)

我在导航栏中有一个条形按钮项,按下时将显示一个UIAlertController样式为.ActionSheet.在iPhone中,它看起来就像我想要的那样.对于iPad,我知道我需要添加
// For iPad, set the pop over bounds
var popOver = optionMenu.popoverPresentationController
popOver?.sourceView = button as UIView
popOver?.sourceRect = (button as UIView).bounds
popOver?.permittedArrowDirections = UIPopoverArrowDirection.Any
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何使用条形按钮项目作为sourceView和sourceRect?我希望popover指向bar按钮项.
我很难显示我的UIAlertController,因为我试图在一个不是ViewController的类中显示它.
我已经尝试过添加它了:
var alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这是行不通的......我找不到任何对我有用的解决方案.