标签: uialertcontroller

如何使用UIAlertController修复运行时错误

我将此代码放在UIVIewController(XCode 6.1,iOS 8.1.1)中:

[UIAlertController showActionSheetInViewController:self
                         withTitle:@"Test Action Sheet"
                         message:NSLocalizedString(@"Are you sure you want to delete ALL appointments?",nil)
                         cancelButtonTitle:@"Cancel"
                         destructiveButtonTitle:@"Yes"
                         otherButtonTitles:@[@"No"]  //  same as Cancel
                         tapBlock:^(UIAlertController *controller, UIAlertAction *action, NSInteger buttonIndex){
                              if (buttonIndex == UIAlertControllerBlocksCancelButtonIndex) {
                                 NSLog(@"Cancel Tapped");
                             } else if (buttonIndex == UIAlertControllerBlocksDestructiveButtonIndex) {
                                 NSLog(@"Delete Tapped");
                             } else if (buttonIndex >= UIAlertControllerBlocksFirstOtherButtonIndex) {
                                 NSLog(@"Other Action Index %ld", (long)buttonIndex - UIAlertControllerBlocksFirstOtherButtonIndex);
                             }
                         }];
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到这个运行时错误:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x7fdfe3324f00>) …

objective-c uialertcontroller ios8.1

6
推荐指数
2
解决办法
5078
查看次数

如果要调用另一个警报控制器,则删除警报控制器

我的应用需要在不同时间向用户显示一些信息.我决定使用AlertControllers,但我无法同时显示两个警报控制器.因此,我需要知道是否显示警报控制器,关闭它并打开另一个警报控制器.

到目前为止我已经这样做了.我正在使用self.presentedViewController检查是否显示AlertController.但我无法弄清楚如何关闭它.我试过了

self.presentedViewController?.removeFromParentViewController()
Run Code Online (Sandbox Code Playgroud)

self.presentedViewController?.delete(self.presentedViewController)
Run Code Online (Sandbox Code Playgroud)

没有运气.有人可以帮帮我吗?谢谢

alert ios swift uialertcontroller

6
推荐指数
1
解决办法
3404
查看次数

当用户使用swift键入时,限制UIAlertController中文本字段的输入?

我发现有关此示例代码如何添加文本框UIAlertController ,但我无法限制用户为限制只输入10个字符,我有一个函数删除最后一个字符时,它是在过去的编辑改变常规文本字段无法检查文本字段UIAlertController.

//Function to Remove the last character

func trimStr(existStr:String)->String{

    var countExistTextChar = countElements(existStr)

    if countExistTextChar > 10 {
        var newStr = ""
        newStr = existStr.substringToIndex(advance(existStr.startIndex,(countExistTextChar-1)))
        return newStr

    }else{
        return existStr
    }

}

 var inputTextField: UITextField?

    //Create the AlertController
    let actionSheetController: UIAlertController = UIAlertController(title: "Alert", message: "Swiftly Now! Choose an option!", preferredStyle: .Alert)

    //Create and add the Cancel action
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void …
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

6
推荐指数
1
解决办法
4953
查看次数

UIAlertController错误更改其他UIImageViews的tintcolor

我有我认为是一个奇怪的iOS8错误.每当我发布一个,UIAlertController我发现它正在改变我UIImageViews使用UIImageRenderingModeAlwaysTemplate图像渲染模式为深灰色的所有色调颜色.无论我是否调整色调,都会发生这种情况UIAlertController.下面找到一个截图(看看气泡角),它们在UIAlertController显示之前是正确的颜色,一旦被解除就会返回正确的颜色.

有谁知道在iOS8中如何防止这种情况?

在此输入图像描述

UIAlertController *alertController = [UIAlertController
                                      alertControllerWithTitle:[NSString stringWithFormat:@"Question ended %@",[endDateFormat stringFromDate:[NSDate dateWithTimeIntervalSince1970:selectedActivity.utc]]]
                                      message:messageText
                                      preferredStyle:UIAlertControllerStyleActionSheet];
[alertController.view setTintColor:[UIColor colorWithHue:240.0/360 saturation:.03 brightness:.58 alpha:1]];

//...Add some actions and then
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

uiimageview tintcolor ios8 uialertcontroller

6
推荐指数
1
解决办法
1000
查看次数

以编程方式在UIAlertController上触发UIAlertAction吗?

关于此主题有两个现有的问题,但它们并不是我所追求的。我为我的应用程序编写了一个Swift应用程序评级提示,其中显示了两个UIAlertController实例,一个实例由另一个实例触发。

我现在正在尝试对此进行单元测试,并试图在测试中达到第二个警报。我编写了一个简单的间谍程序来检查第一个控制器,但是我想一种触发第一个警报的动作的方法,该警报又显示第二个。

我已经尝试过了alert.actions.first?.accessibilityActivate(),但是似乎并没有在该操作的处理程序中打断–这就是我所追求的。

unit-testing swift uialertcontroller uialertaction

6
推荐指数
2
解决办法
3294
查看次数

如何使警报控制器中的可点击链接迅速

我的应用截图

我想要这样的警报对话框。其中包含一个可点击的链接,例如蓝色突出显示的文本。当用户单击该文本时,它将在浏览器中打开一个链接。为此,我正在使用第三方库SimpleAlert

这是我的代码...

func popUpMsg(){

    let msg = "\n Hi Rahul! Welcome back to the early access queue for the app, Once you've been accepted into the beta, we'll notify you using the contact info you have on file with Facebook. \n\n But just a second, if you haven't already done so, you can increase your odds of jumping ahead in the queue by telling us a little about yourself. Please complete our 4-question survey to give it a shot. …
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

6
推荐指数
0
解决办法
4299
查看次数

UIAlertController没有消失

我没有弄到我的代码有什么问题.我只是用"确定"按钮显示警报,当用户点击"确定"时,警报就应该开始.但它并没有消失.使用Swift3进行编程.viewDidAppear()这个代码是正确的地方吗?或者我做错了什么?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)          
    alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
    present(alertController, animated: true, completion: nil)  
}
Run Code Online (Sandbox Code Playgroud)

更新:当我将相同的代码放在其他控制器中时,它工作.在原始控制器中,在viewDidLoad()中,我有一个Async如下调用.这是因为这个问题吗?

DispatchQueue.global(qos: .background).async {
    self.getDetails(onCompletion: {(json: JSON) in

    let dict = self.convertToDictionary(text: json.stringValue)

        DispatchQueue.main.async {

            self.activityIndicator.stopAnimating()
            UIApplication.shared.endIgnoringInteractionEvents()

            //Other UI update operation

        }
    })
}    
Run Code Online (Sandbox Code Playgroud)

我还覆盖viewWillDisappear()viewWillAppear(),只需设定屏幕的标题.

viewdidappear ios uialertcontroller swift3

6
推荐指数
2
解决办法
628
查看次数

如何在iOS中创建UIActionSheet的背景视图?

我希望有一个UIActionSheet自定义,UIAlertAction但似乎自定义UIAlertAction不合法.

UIAlertController类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.

所以我正在尝试创建一个看起来完全一样的视图UIActionSheet.通过使用Debug View Hierarchy,我可以知道Apple如何应用层次结构,约束,颜色UIActionSheet来完成他们所做的事情.

在此输入图像描述

我可以创建除了UIActionSheet背景之外的所有东西.这是一个包含非透明视图和视图的视图UIVisualEffectView.

UIVisualEffectView重叠不透明的看法,但不知何故UIVisualEffectView仍然有效.

在此输入图像描述

UIVisualEffectView下面有一个不透明的时候怎么还能工作呢?如果有可能,我怎么能做这样的事情?

注意:背景UIActionSheet不仅仅是一个UIVisualEffectView.请不要给出这样的答案.

objective-c ios swift uialertcontroller

6
推荐指数
1
解决办法
607
查看次数

扩展UIAlertController方便初始化警告

当我定义一个UIAlertController便利初始化器时:

extension UIAlertController {
    convenience init(message: String?) {
        self.init(title: nil, message: message, preferredStyle: .Alert)
        self.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
    }
}
Run Code Online (Sandbox Code Playgroud)

并在我的子类中的按钮操作中使用它UIViewController:

func buttonAction(button: UIButton) {
    let alert = UIAlertController(dictionary: nil, error: nil, handler: nil)
    presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

然后单击模拟器上的那个按钮,我收到一个警告:

尝试在取消分配时加载视图控制器的视图是不允许的,并且可能导致未定义的行为(UIAlertController)

但是,如果不使用便利初始化程序,我不会收到警告,我使用全局函数:

func UIAlertControllerWithDictionary(message: String?) -> UIAlertController {
    let alert = UIAlertController(title: nil, message: message, preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
    return alert
}
Run Code Online (Sandbox Code Playgroud)

我已将此报告给Apple作为iOS SDK错误.

在它修复之前,可以忽略警告并使用便利初始化程序吗?

warnings initialization ios swift uialertcontroller

5
推荐指数
1
解决办法
1883
查看次数

如何在Swift中更改UIAlertController中UITextField的高度?

我添加了UITextField一个UIAlertController.我想更改文本字段的高度.我试过这种方式:

let alertController = UIAlertController(title: "Comments", message: "Write your comments here", preferredStyle: UIAlertControllerStyle.alert)
alertController.addTextField { (textField : UITextField) -> Void in
    var frame: CGRect = textField.frame
    frame.size.height = 100
    textField.frame = frame
    textField.placeholder = "comment"
    print(textField.frame.size.height)
}

let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (result : UIAlertAction) -> Void in
}

let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}

alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

它不起作用.

uitextfield ios swift uialertcontroller

5
推荐指数
2
解决办法
4443
查看次数