Tag: uialertaction

UIAlertAction的处理程序有点太迟了 – 我怎么能立即做到这一点?

我正在尝试(…)为添加到UIAlertController的button添加声音效果。 我在处理程序中发出了一个声音效果,但实际上有点太迟了。 声音像0.5秒太晚了。 警报即将解散后 ,我希望声音能够解除,而不是在解散之后解除。 使用UIAlertView可以处理使用alertWillDismiss …而不是alertDidDismiss。 我错过了什么?

在UIAlertController的文本字段中select文本

我需要在UIAlertController出现后立即select文本字段的文本。 但是,我在标准UITextField中select文本的方式在这里不起作用。 这是我的尝试,但我似乎无法得到它的工作。 let ac = UIAlertController(title: "Rename", message: nil, preferredStyle: .Alert) ac.addTextFieldWithConfigurationHandler({ [] (textField: UITextField) in textField.selectedTextRange = textField.textRangeFromPosition(textField.beginningOfDocument, toPosition: textField.endOfDocument) textField.text = "filename.dat" }) ac.addAction(UIAlertAction(title: "CANCEL", style: .Cancel, handler: nil)) ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: { [] Void in // do something })) dispatch_async(dispatch_get_main_queue(), { self.presentViewController(ac, animated: true, completion: nil) }) 有任何想法吗?

当应用程序在Swift 2.0后台运行时发送本地通知

我试图在用户最小化应用程序时(通过点击iPhone的主页button或locking手机)发送“推送通知样式”警报。 我的应用程序不断分析一个XML文件(每10秒钟),我希望应用程序继续运行,以便在程序中遇到一些条件时向用户发送本地通知,即使用户已经最小化应用程序或locking了它们电话。 我已经从教程中反弹,每个人似乎都“安排”了一个通知,但是这对我来说不起作用,因为我的通知不是基于时间的,而是基于满足条件的。 到目前为止我所做的是: AppDelegate.swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)) return true } MapViewController.swift // Some function func someFunction(delta: Int) { if delta < 100 { // Send alert to user if app is open let […]

UIAlertAction处理程序在延迟之后运行

我试图将我的UIAlertViews更改为UIAlertControllers。 我为此设置了这个动作: UIAlertAction *undoStopAction = [UIAlertAction actionWithTitle:@"Undo Stop" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self undoStop]; }]; 但是,处理程序不会运行,直到动作被点击后一秒左右。 有什么办法可以加速吗?

是否应该在UIAlertAction的处理程序中把自己强加给?

在编写UIAlertAction的handler闭包时,对self的引用是否应该是强壮的(默认), weak还是unowned ? 有一些post与这个话题有关( 1,2,3,4 ),但是我真的不明白他们在这种情况下如何提供帮助。 我们来关注一下这个典型的代码: func tappedQuitButton() { let alert = UIAlertController(title: "Confirm quit", message: nil, preferredStyle: .ActionSheet) let quitAction = UIAlertAction(title: "Quit", style: .Default) { (action) in self.dismissViewControllerAnimated(true, completion: nil) } alert.addAction(quitAction) let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in self.dismissViewControllerAnimated(true, completion: nil) } alert.addAction(cancelAction) presentViewController(alert, animated: true, completion: nil) […]

如何从SKScene展示UIAlertController

我在Spritekit工作,我试图从我的SKScene提出一个UIAlertController,但我遇到麻烦。 我看过几个教程,但是没有一个UIAlertController教程是专门针对Spritekit的。 我不断地看到下面的代码,但它并没有效果,因为SKScene不是一个UIViewController。 [self presentViewController:self animated:YES completion:nil]; 我有下面的相关代码的其余部分。 任何人都可以帮我在我的SKScene上展示我的UIAlerController。 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"You Lose!" message:@"Do You Want To Beat This Level?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *CancelButton = [UIAlertAction actionWithTitle:@"GiveUp" style:UIAlertControllerStyleAlert handler:<#^(UIAlertAction *action)handler#>]

如何编辑UIAlertAction文本的字体大小和颜色

如何编辑UIAlertAction文字大小和颜色? 我已经采取了一个UIAlertController如何编辑大小。 这我smy代码 UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Do you wish to logout?" message:@"" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *logOut = [UIAlertAction actionWithTitle:@"Log Out" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}]; 现在我想要我的“注销”字体大小为22,绿色,半色的文本。