GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Project 5: UIAlertController not Appreaing

Forums > 100 Days of Swift

@objc func promptForAnswer() { let ac = UIAlertController(title: "Enter Answer", message: nil, preferredStyle: .alert)

    ac.addTextField()

    let submitAction = UIAlertAction(title: "Submit", style: .default) {
        [weak self, weak ac] action in
        guard let answer = ac?.textFields?[0].text else {return}
        self?.submit(answer)
    }

    ac.addAction(submitAction)
    present(ac, animated: true)
}

With ac.addTexfield() the alert controller isn't appearing, However, without that line and the closure, the alert is appearing. There's no error, the alert just doesnt appear.

However, in the console I do see Class _PointQueue is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x10fe0b628) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x12fd836b8). One of the two will be used. Which one is undefined.

Could anyone help please?

3      

Hi there! It is difficult to say with having only part of the code. Basically, I have the same ->

  @objc func promptForAnswer() {
    let ac = UIAlertController(title: "Enter answer", message: nil, preferredStyle: .alert)
    ac.addTextField()

    let submitAction = UIAlertAction(title: "Submit", style: .default) { [weak self, weak ac] _ in
      guard let answer = ac?.textFields?[0].text else { return }
      self?.submit(answer)
    }

    ac.addAction(submitAction)
    present(ac, animated: true)

  }

and this function is called by invoking it from navigation right bar button like that - you should have it in viewDidLoad() ->

navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(promptForAnswer))

3      

Thank you @ygeras , I have the same code as yours, even the invoking of the rightBarButton in the viewDidLoad(). I'm not sure, why it doesn't appear with textfield method ac.addTextField() . The alert appears If I just comment that and the closure of the UIAlertAction.

3      

Try to Clean Build Folder by pressing Shift+Cmd+K. As an option try to add print("TextField added") or other print statements in the flow to check where the issue is...

 let ac = UIAlertController(title: "Enter answer", message: nil, preferredStyle: .alert)
    ac.addTextField()

    print("TextField added")

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.