Add an alertcontroller in a global swift file?

Add an alertcontroller in a global swift file?

Content Index :

Add an alertcontroller in a global swift file?
Tag : ios , By : ArmHead
Date : November 24 2020, 05:47 AM

hop of those help? I am trying to create a alert box inside the swift file other than the UIViewController file. but I could not create it.
extension UIViewController {
     func showAlert(message: String, title: String = "") {
        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        self.present(alertController, animated: true, completion: nil)
from.showAlert(message:"Your message", title: "Title")

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

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
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in }
    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
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in
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
        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

Tag : ios , By : Comfly
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)

            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


    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (UIAlertAction) in



    present(alert, animated: true, completion: nil)

Related Posts Related QUESTIONS :
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • UserDefaults Binding with Toggle in SwiftUI
  • How to create a color with an alpha value using SwiftUI?
  • SwiftUI creates destination views before the user navigates to them
  • Streaming video from https with AVPlayer causes initial delay
  • Tap Action not working when Color is clear SwiftUI
  • SwiftUI NavigationButton: How to navigate to different destinations
  • Supported default light/dark mode colors for Color vs UIColor
  • XCUITest wait for a cell with a specific static text inside it
  • Not able to enable Development mode on iOS 13
  • How to hide the home indicator with SwiftUI?
  • How to write if condition with using label text (Int) values
  • Swift Cannot use instance member within property initializer
  • Issue while getting the frame of the keyboard
  • dynamicMemberLoookup ExpressibleByStringLiteral parameter swift
  • iOS Unity Firebase Messenger Xcode Compile Error: FIRDynamicLinks
  • Firebase Storage Image Cache not updating SWIFT
  • unhandled js exception: application main has not been registered expo TestFlight
  • App freezes on IOS when navigate to another screen - React Navigation
  • How to create haptic feedback for a Button in SwiftUI?
  • How can I achieve automatic scrolling in my text view when text comes down to the keyboard level in Swift?
  • how to get the location with the CLLocationManager every 10 secondes?
  • Calling completion handler of a function from Timer selector function Swift
  • How to make SwiftUI view fullscreen?
  • RAM, JSC, Views, UI and JS usage table appearing whenever I launch my react native app. How to remove this table?
  • Change status bar background color using UIStatusBarManager
  • Should we make tapGesture component an IBAction or IBOutlet to capture the tap event?
  • Iframe automatically goes full screen using Ionic 3.9.2 on iOS
  • How to calculate score out of 1000 given some seconds (In Double)
  • How to calculate time (minutes) between two dates in swift?
  • There was problem loading requested app.it looks like you may be using LAN URL
  • Swift circular corners doesn't work properly on different screen sizes
  • How change .navigationBarTitle font in SwiftUI?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com