uialertcontroller

禁止UIAlertController的dimiss

最后都变了- 提交于 2019-12-01 18:48:36
标签: objectvie-c Runtime UIAlertController是在iOS 8.0以后才出现的,用于弹窗提示的视图,在8.0 之前使用的是UIAlertView。UIAlertController有两种模式:Alert和Sheet。只有在Alert模式下,才可以向UIAlertController中添加UITextField,否则会崩溃。默认情况都是点击UIAlertController上的按钮之后,执行相应回调最后dismiss掉。在没有UITextField的时候,这样没有任何问题,但是在UITextField存在的情况下,且需要对输入进行合法性验证,只有输入合法时点击UIAlertController才进行回调处理。按照系统的默认方式在点击UIAlertController按钮时流程为: 如果输入合法,执行处理回调;如果输入不合法,给出提示,不执行回调。 UIAlertController dismiss 这里不管输入合法与否,都是会dismiss,如何做到输入不合法,不dismiss,直到输入合法才dismiss。目前能想到的只有两种方法: 自己重写一个UIAlertController,好处是可以根据实际需求灵活配置,包括大小,颜色之类的,坏处是工作量比较大。 从系统UIAlertController入手,根据方法调用过程hook相关方法。

Runtime Exception coming when show UIAlertController(actionsheet) iOS8

丶灬走出姿态 提交于 2019-12-01 11:02:43
Runtime exception is coming when i show UIAlertController(ActionSheet) in iOS8 Beta5+ Xcode6 . This Bug is only happening in iPad Devices. I'm getting bellow exception when using the UIAlertController. * Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x15794370>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.' My Code for display ActionSheet as follows // Cancel Button UIAlertAction *actionCancel = [UIAlertAction actionWithTitle

XCode 7 UI Testing: Dismissal of system-generated UIAlertController does not work

坚强是说给别人听的谎言 提交于 2019-12-01 10:11:57
I have a UI test which involves the dismissal of a system-generated UIAlertController . This alert asks the user for the permission to access the device's calendar. The objective of the test is the behaviour after a tap on the OK button: 1 let app = XCUIApplication() ... // this code was basically generated by the recording feature of XCode 7 2 app.alerts.elementBoundByIndex(0).collectionViews.buttons["OK"].tap() Now, instead of clicking the OK button, line 2 makes the simulator tap onto the first button which happens to be the Cancel button... Additionally, I found out that the testing

Displaying a UIAlertController in GameScene (SpriteKit/Swift)

北城余情 提交于 2019-12-01 09:38:34
问题 The simple way to display a UIAlertView, in swift is: let alert = UIAlertView() alert.title = "Alert!" alert.message = "A wise message" alert.addButtonWithTitle("Ok, thank you") alert.show() But this is now depreciated in iOS 9 and recommends using UIAlertController : let myAlert: UIAlertController = UIAlertController(title: "Alert!", message: "Oh! Fancy", preferredStyle: .Alert) myAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) self.presentViewController(myAlert,

Accessing UIAlertControllers textField

被刻印的时光 ゝ 提交于 2019-12-01 09:01:07
I'm having trouble accessing an UIAlertController's textField from within a handler action, I think. I've googled the error but didn't get too much out of it. I'm using Swift with Xcode 6.0.1. Here's the error: '[AnyObject]?' does not have a member named 'subscript' @IBAction func addPressed(sender: UIBarButtonItem) { var alert = UIAlertController(title: "New Event", message: "Name of the event?", preferredStyle: .ActionSheet) alert.addTextFieldWithConfigurationHandler(){ textField in textField.placeholder = "Christmas" textField.becomeFirstResponder() } alert.addAction(UIAlertAction(title:

XCode 7 UI Testing: Dismissal of system-generated UIAlertController does not work

六月ゝ 毕业季﹏ 提交于 2019-12-01 08:52:03
问题 I have a UI test which involves the dismissal of a system-generated UIAlertController . This alert asks the user for the permission to access the device's calendar. The objective of the test is the behaviour after a tap on the OK button: 1 let app = XCUIApplication() ... // this code was basically generated by the recording feature of XCode 7 2 app.alerts.elementBoundByIndex(0).collectionViews.buttons["OK"].tap() Now, instead of clicking the OK button, line 2 makes the simulator tap onto the

UIAlertController message getting truncated to one line

丶灬走出姿态 提交于 2019-12-01 08:09:12
问题 In my app, while presenting the UIAlertController it's truncating the message to one line. How to make it display to show full text with word wrap. Here is my code let alert = UIAlertController(title: title, message:"Long text" , preferredStyle: UIAlertControllerStyle.alert) let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil) alert.addAction(okAction) self.present(alert, animated: true, completion: nil) 回答1: I found the issue.I was overriding the UILabel

Runtime Exception coming when show UIAlertController(actionsheet) iOS8

为君一笑 提交于 2019-12-01 07:36:47
问题 Runtime exception is coming when i show UIAlertController(ActionSheet) in iOS8 Beta5+ Xcode6 . This Bug is only happening in iPad Devices. I'm getting bellow exception when using the UIAlertController. * Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x15794370>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.' My Code for display

UIAlertController subclass issue swift

扶醉桌前 提交于 2019-12-01 07:35:40
I want to create a UIAlertController's subclass but I'm going crazy because I have problem with constructor, this is my subclass: class loginAlert : UIAlertController { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } } I think that this subclass must have the constructor : UIAlertController(title: String, message: String, preferredStyle: UIAlertControllerStyle) , because it's a subclass of UIAlertController , but when I do loginAlert(title: "test", message: "test", preferredStyle: .Alert) I get error , why where Do I wrong? From the UIAlertController Class Reference :

UIActionSheet/UIAlertController multiline text

雨燕双飞 提交于 2019-12-01 06:37:34
This is the code I am writing to display UIActionSheet . actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"updateresponseforrecurring", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles: NSLocalizedString(@"updateresponseonlyforthis", nil), NSLocalizedString(@"updateresponseforallactivities", nil), nil]; actionSheet.tag = 2; [actionSheet showInView:[UIApplication sharedApplication].keyWindow]; This is what I get using this : Clearly, second option is longer and thus the size gets smaller to accommodate the