Swift shouldSelectViewController using alertController
Tag : swift , By : micate
Date : March 29 2020, 07:55 AM
wish helps you You can try setting the selecedIndex property of the UITabBarController. Your new if statement: if (viewController is Trove.HomeViewController) {
let alertController = UIAlertController(title: "Logout", message: "Are you sure you want to log out?", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Logout", style: .Default) { (action) in
tabBarController.selectedIndex = 0 //CHANGE ME
}
alertController.addAction(okAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in }
alertController.addAction(cancelAction)
tabBarController.presentViewController(alertController, animated: true)
return false
}
|
show the textField in the alertController in swift
Tag : ios , By : George Handlin
Date : March 29 2020, 07:55 AM
I wish this help you Just now I wrote the code which is provided below. I would like to produce the output for the following code but it crashes when I run it, and it shows nil. , Code for Adding textField in UIALertController : let alertController = UIAlertController(title: "PlainTextStyle", message: "PlainTextStyle AlertView.", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addTextFieldWithConfigurationHandler { (textField : UITextField) -> Void in
textField.placeholder = "Login"
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (result : UIAlertAction) -> Void in
print("Cancel")
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in
print(alertController.textFields?.first?.text)
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
let alertController = UIAlertController(title: "PlainTextStyle", message: "PlainTextStyle AlertView.", preferredStyle: UIAlertControllerStyle.alert)
alertController.addTextField { (textField : UITextField) -> Void in
textField.placeholder = "Login"
}
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)
|
Add tableview in AlertController dynamically in swift , how?
Tag : swift , By : meehan
Date : March 29 2020, 07:55 AM
Hope that helps Create a new UIViewController, and before presenting it set modalPresentationStyle property to be UIModalPresentationOverCurrentContext. The UIViewController's view must have set clear color as background color and to be overlaid by a UIImageView with alpha 0.5 and has gray color. This will create the semi-transparent effect, then add other UI elements you need (table view, buttons, etc). Let's say you have CustomViewController for displaying the content above you described. You'll present it using the following statments: let customVC = CustomViewController()
customVC.modalPresentationStyle = .OverCurrentContext
presentViewController(customVC, animated: false, completion: nil)
|
How to change the style of AlertController Swift 3
Date : March 29 2020, 07:55 AM
Hope this helps I think you will need to create a custom alert controller for this behaviour. I would start by subclassing UIView, then layout your subviews accordingly
|
Swift Use AlertController to add annotation on mapView
Tag : ios , By : ChaseVoid
Date : March 29 2020, 07:55 AM
Does that help Just store the touch points before UIAlertController Presentation and use that in UIAlterAction because when Alert popover/present while longpress it cannot able to save/get touch point that why touch points inside UIAlterAction is always 0,0. func longpress(gestureRecognizer: UIGestureRecognizer) {
let touchpointtemp = gestureRecognizer.location(in: self.map_home)
let alert = UIAlertController(title: "New Place", message: "Enter a name", preferredStyle: UIAlertControllerStyle.alert)
alert.addTextField { (textField: UITextField) in
textField.placeholder = "Name"
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (UIAlertAction) in
if let tempPlace = alert.textFields?[0].text {
let place = tempPlace
let touchpoint = touchpointtemp
let coordinate = self.map_home.convert(touchpoint, toCoordinateFrom: self.map_home)
print(coordinate)
let annotation = MKPointAnnotation()
let latitude = coordinate.latitude
let longitude = coordinate.longitude
annotation.title = place
annotation.subtitle = "Lat " + (String(format: "%.2f", latitude) + " Lon " + String(format: "%.2f", longitude))
annotation.coordinate = coordinate
self.map_home.addAnnotation(annotation)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (UIAlertAction) in
}
alert.addAction(okAction)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
}
|