How to dismiss UIAlertController when tap outside the UIAlertController?

If you are targeting devices having iOS > 9.3 and using Swift and preferredStyle is Alert you can use snippet as below: func showAlertBtnClicked(sender: UIButton) { let alert = UIAlertController(title: “This is title”, message: “This is message”, preferredStyle: .Alert) self.presentViewController(alert, animated: true, completion:{ alert.view.superview?.userInteractionEnabled = true alert.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertControllerBackgroundTapped))) }) } func alertControllerBackgroundTapped() { … Read more

Unable to add UITextField to UIAlertView on iOS7…works in iOS 6

You can’t easily alter the view hierarchy of a UIAlertView in iOS 7. (Nor should you; the documentation specifically tells you not to.) Head over to the developer forums to see a long discussion about it. One alternative in your case is to set alert.alertViewStyle = UIAlertViewStylePlainTextInput; This will add a text field for you. … Read more

Display UIViewController as Popup in iPhone

NOTE : This solution is broken in iOS 8. I will post new solution ASAP. I am going to answer here using storyboard but it is also possible without storyboard. Init: Create two UIViewController in storyboard. lets say FirstViewController which is normal and SecondViewController which will be the popup. Modal Segue: Put UIButton in FirstViewController … Read more

Create UIActionSheet ‘otherButtons’ by passing in array, not varlist

I got this to work (you just need to, be ok with a regular button, and just add it after : NSArray *array = @[@”1st Button”,@”2nd Button”,@”3rd Button”,@”4th Button”]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@”Title Here” delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; // ObjC Fast Enumeration for (NSString *title in array) { [actionSheet addButtonWithTitle:title]; } actionSheet.cancelButtonIndex = … Read more

Adding a simple UIAlertView

When you want the alert to show, do this: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”ROFL” message:@”Dee dee doo doo.” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil]; [alert show]; // If you’re not using ARC, you will need to release the alert view. // [alert release]; If you want to do something when the button is clicked, implement this delegate … Read more

Writing handler for UIAlertAction

Instead of self in your handler, put (alert: UIAlertAction!). This should make your code look like this alert.addAction(UIAlertAction(title: “Okay”, style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in println(“Foo”)})) this is the proper way to define handlers in Swift. As Brian pointed out below, there are also easier ways to define these handlers. Using his methods is discussed … Read more

UIAlertView first deprecated IOS 9

From iOS8 Apple provide new UIAlertController class which you can use instead of UIAlertView which is now deprecated, it is also stated in deprecation message: UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead So you should use something like this UIAlertController * alert = [UIAlertController alertControllerWithTitle:@”Title” message:@”Message” preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* yesButton = [UIAlertAction … Read more

UIAlertController custom font, size, color

Not sure if this is against private APIs/properties but using KVC works for me on ios8 UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@”Dont care what goes here, since we’re about to change below” message:@”” preferredStyle:UIAlertControllerStyleActionSheet]; NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@”Presenting the great… Hulk Hogan!”]; [hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50.0] range:NSMakeRange(24, 11)]; [alertVC setValue:hogan forKey:@”attributedTitle”]; UIAlertAction *button = … Read more

How would I create a UIAlertView in Swift?

From the UIAlertView class: // UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead On iOS 8, you can do this: let alert = UIAlertController(title: “Alert”, message: “Message”, preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: “Click”, style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) Now UIAlertController is a single class for creating and interacting with what … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)