标签: uialertcontroller

将图像添加到UIAlertController

这是我的警报,完美无缺.我想在警报显示时向警报添加一个图像,如果它有所不同,我会在SpriteKit中的SKScene中.

var alertController = UIAlertController(title: "How to Skate", message: "Tap the screen to perform a trick and jump over the obsticles (You can grind on rails) The game will end when you hit a highlighted red, orange or yellow obstacle. That's it! + Image", preferredStyle: UIAlertControllerStyle.Alert)     
alertController.addAction(UIAlertAction(title: "Cool!", style: UIAlertActionStyle.Cancel, handler: nil))
self.view?.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

8
推荐指数
2
解决办法
2万
查看次数

想在UIAlertController或UIPopoverController Swift中显示UIPickerView?

我想在UIAlertController或UIPopoverController中显示UIPickerView,我是iOS新手,请在这里给我一些示例代码.

我搜索了他们但找不到任何满意的答案.我不想在UIActionSheet上这样做,因为它在iOS 9中已被弃用.我也希望它在Swift中而不是在Obj-C中.我尝试了下面的例子,但它不适合我.

http://makeapppie.com/2014/08/30/the-swift-swift-tutorials-adding-modal-views-and-popovers/

uipickerview uipopovercontroller ios swift uialertcontroller

8
推荐指数
2
解决办法
2万
查看次数

显示UIAlertViewController时,XCODE iphone 6 plus和6s plus会显示警告

我是iOS开发的新手.我试图显示UIAlertController单击按钮的时间(故事板为空,故事板中只有1个按钮),使用下面的代码

@IBAction func showAlert(sender: UIBarButtonItem) {
  let alert = UIAlertController(
    title: "Create new",
    message: "Hi",
    preferredStyle: UIAlertControllerStyle.Alert
  )

  let createAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)
  let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

  alert.addAction(createAction)
  alert.addAction(cancelAction)
  alert.addTextFieldWithConfigurationHandler {
    $0.placeholder = "Test placeholder"
  }

  presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

iphone 5,5s,6,6s不显示警告,但iphone 6plus和6s plus显示警告

2015-10-20 22:38:54.007 TestApp [3128:48601]未定义UICollectionViewFlowLayout的行为,因为:2015-10-20 22:38:54.008 TestApp [3128:48601]项目高度必须小于UICollectionView的高度减去该部分的顶部和底部值,减去内容插入的顶部和底部值.2015-10-20 22:38:54.008 TestApp [3128:48601]相关的UICollectionViewFlowLayout实例是<_UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>,它附加到; layer =; contentOffset:{0,0}; contentSize:{0,0}>集合视图布局:<_ UIAlertControllerCollectionViewFlowLayout:0x7fd6b8582d90>.

如果我删除文本字段UIAlertController或删除2个按钮(保持显示文本字段),它不会显示警告.任何解释为什么会这样?如何修复警告?

iphone ios swift uialertcontroller

8
推荐指数
1
解决办法
2067
查看次数

在UIAlertController的文本字段中选择文本

我需要在UIAlertController出现后立即选择文本字段的文本.但是,我在标准UITextField中选择文本的方式在此处不起作用.

这就是我尝试过的,但我似乎无法让它发挥作用.

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)
})
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

ios swift uialertcontroller uialertaction

8
推荐指数
3
解决办法
1883
查看次数

如何在全球范围内创建uialertcontroller

我正在尝试uialertcontrollerConfig.swift文件中创建如下.

static func showAlertMessage(titleStr:String, messageStr:String) -> Void {
    let window : UIWindow?
    let alert = UIAlertController(title: titleStr, message: messageStr, preferredStyle: UIAlertControllerStyle.Alert);
    self.window!.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

问题是我发现了问题 self.window!.

类型'Config'没有会员'窗口'

请让我知道如何解决这个问题.

ios swift uialertcontroller

8
推荐指数
3
解决办法
1万
查看次数

警告:UIAlertController已经呈现

我是swift和XCode的新手所以请原谅我可能非常混乱的代码!运行我的代码时,我收到以下警告:警告:尝试呈现已经呈现的内容

我已经检查了论坛并发现了一个关于该问题的帖子....我应用了建议的帮助,如:

if presentedViewController !== nil {
     self.presentViewController(alertController, animated: true, completion: nil)
} else{
     self.dismissViewControllerAnimated(false, completion: nil)
     self.presentViewController(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

但是,它仍然给了我同样的警告....所以我想我一定做错了.如果有人可以帮助我,那将是很棒的:)如果有任何关于我如何"清理"我的代码的建议,我感激不尽:)

import UIKit

class ViewController: UIViewController {

@IBOutlet var Label: UILabel!

@IBOutlet var ukFlag: UITextView!

@IBOutlet var movie: UITextView!

@IBOutlet var piano: UITextView!

@IBOutlet var book: UITextView!

@IBOutlet var dance: UITextView!

@IBOutlet var paint: UITextView!

@IBOutlet var row: UITextView!

@IBOutlet var envelope: UITextView!

@IBOutlet var dragon: UITextView!

@IBOutlet var instagram: UITextView!


func londonPuzzle(sender: UIPanGestureRecognizer) {
    let translation …
Run Code Online (Sandbox Code Playgroud)

xcode warnings ios swift uialertcontroller

8
推荐指数
1
解决办法
1万
查看次数

解雇由模态视图控制器呈现的UIAlertController

我似乎遇到了类似于一个未解决的问题中的问题:UIAlertController解雇他的presentViewController

我在普通的UIViewController上呈现模态视图控制器.然后我在该模态视图控制器上弹出警报.当我按"ok"关闭警报(使用下面的代码生成)时,模态视图控制器也被解除.

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK"
                                             style:UIAlertActionStyleDefault 
                                           handler:^(UIAlertAction *action{ 
                                                    [self dismissViewControllerAnimated: YES completion: nil];}];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sign up problem."
                                                               message:@"Some fields are empty. Please check your inputs and try again."
                                                        preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我该如何解除警报?

我意识到我可以通过使用导航控制器类型设置而隐藏导航栏来避免这个问题,所以我得到了与模态视图控制器相同的感觉,但这看起来很傻.谢谢.

objective-c ios uialertcontroller

7
推荐指数
1
解决办法
2万
查看次数

LAContext更改UIAlertController按钮标题

我已将TouchID合并到我的应用中LAContext,如下所示:

在此输入图像描述

但是,我想要从"输入密码"更改按钮标题的名称,以输入"输入安全代码"(或类似的东西),如下所示:

在此输入图像描述

如何更改按钮标题?

这是LAContext 文档,这是我的代码:

var touchIDContext = LAContext()

if touchIDContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &msgError) {
   touchIDContext.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: touchIDMessage) {
        (success: Bool, error: NSError!) -> Void in

        if success {
            println("Success")
        } else {
            println("Error: \(error)")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ios touch-id swift uialertcontroller

7
推荐指数
1
解决办法
2727
查看次数

如何在iOS8的UIAlertController中自定义UIAlertAction?

我需要在Action表项中添加图像UIAlertController.我添加使用:

UIImage *image = [UIImage imageNamed:@"icon.png"];
[alertAction setValue:image forKey:@"image"];
Run Code Online (Sandbox Code Playgroud)

结果如下:

UIActionSheet

问题是: 我需要图像和文本居中对齐并调整取消按钮的高度

我该怎么做,请分享一些代码.

谢谢!

objective-c ios8 uialertcontroller

7
推荐指数
1
解决办法
6466
查看次数

UIAlertController会自动消失

所以我有一个使用以下代码创建的UIAlertController:

let alertView = UIAlertController(title: "Warning", message: "You have made  changes to \(workoutTemplate!.name). Do you wish to overwrite these changes?", preferredStyle: UIAlertControllerStyle.ActionSheet)

            alertView.addAction(UIAlertAction(title: "Yes, Overwrite", style: UIAlertActionStyle.Destructive, handler: {(alert: UIAlertAction!) in

                //... some code

            }))

            alertView.addAction(UIAlertAction(title: "No, Rename", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in

                   //..some more code                     
            }))

self.presentViewController(alertView, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

我已将警报控制器设置为按下按钮显示,但警报会自动消失:

在此输入图像描述

编辑:发现问题!这对我来说是一个愚蠢的疏忽.上面的代码在交换机中.转换后,我立刻打了个self.dismissViewController()电话.我遗漏了一个else声明,VC在呈现AlertController后试图解雇自己.但是,由于AlertController在此调用时位于导航堆栈的顶部,因此它被解除了.

ios swift uialertcontroller

7
推荐指数
0
解决办法
1908
查看次数