• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Alerts in Xcode 11
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alerts in Xcode 11


  • Subject: Re: Alerts in Xcode 11
  • From: davelist--- via Cocoa-dev <email@hidden>
  • Date: Wed, 9 Oct 2019 10:40:25 -0400

I'm by no means an expert but if I understand what you're trying to do, I think
the approach I would take is to make an extension on UIViewController:

extension UIViewController {
    func notificationAlert(_ msg1: String, _ msg2: String) {

        // create the UIAlertAlertController
        // and then do as David Duncan said and do:
        self.present(<alert controller>, animated: <true/false> completion: …)
    }
}

Now all your UIViewController subclasses can call that method (and because it's
a method, they have access to self which is a subclass of UIViewController).

HTH,
Dave


> On Sep 30, 2019, at 11:27 PM, Doug Hardie via Cocoa-dev
> <email@hidden> wrote:
>
> I tried that and swift complains that self is not defined.  This is not in a
> view controller but a stand alone function used in many view controllers.
> Generally it is used during a segue, but I added one in a view controller to
> a button action, not part of a segue and it dismissed the alert also.
>
> -- Doug
>
>> On 30 September 2019, at 19:48, David Duncan <email@hidden> wrote:
>>
>> Instead of creating a new window and a root view controller in order to
>> present your alert, just use (assuming self is a UIViewController)
>> self.present(<alert controller>, animated: <true/false> completion: …)
>>
>>> On Sep 30, 2019, at 5:48 PM, Doug Hardie <email@hidden> wrote:
>>>
>>> Not sure how to do that.  It's not in any view controller as it is used in
>>> virtually all of the various view controllers.  That's why I wanted it as a
>>> function.
>>>
>>> -- Doug
>>>
>>>> On 30 September 2019, at 14:44, David Duncan <email@hidden>
>>>> wrote:
>>>>
>>>> What happens if you present it over your normal view controller hierarchy
>>>> instead of using another window?
>>>>
>>>> Has your application adopted UIWindowScene?
>>>>
>>>>> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev
>>>>> <email@hidden> wrote:
>>>>>
>>>>> I have some code that presents an alert to the user with information they
>>>>> need, and an OK button to clear it.  It works fine in the previous Xcode
>>>>> versions.  However, after upgrading to 11, it now displays the alert and
>>>>> then immediately clears it.  This happens both in the simulator and on a
>>>>> real device.  I have played around with the code and can't figure out how
>>>>> to make it leave the alert on the screen.  This is in Swift.  It is a
>>>>> function that is called from numerous places in the app.
>>>>>
>>>>> func NotificationAlert (_ msg1: String, _ msg2: String) {
>>>>> let ErrorAlert = UIAlertController(title: msg1, message: msg2,
>>>>> preferredStyle: .alert)
>>>>> let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>>>>> ErrorAlert.addAction(dismiss)
>>>>> ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
>>>>> }
>>>>>
>>>>> extension UIAlertController {
>>>>> func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>>>>>    let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>>>>>    alertWindow.rootViewController = UIViewController()
>>>>>    alertWindow.windowLevel = UIWindow.Level.alert + 1;
>>>>>    alertWindow.makeKeyAndVisible()
>>>>>    alertWindow.rootViewController?.present(self, animated: animated,
>>>>> completion: completion)
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> -- Doug
>>>>>
>>>>> _______________________________________________
>>>>>
>>>>> Cocoa-dev mailing list (email@hidden)
>>>>>
>>>>> Please do not post admin requests or moderator comments to the list.
>>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>>
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>
>>>>> This email sent to email@hidden
>>>>
>>>
>>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Alerts in Xcode 11
      • From: Doug Hardie via Cocoa-dev <email@hidden>
  • Prev by Date: Re: iOS play microphone to headphones
  • Next by Date: Re: Alerts in Xcode 11
  • Previous by thread: Re: iOS play microphone to headphones
  • Next by thread: Re: Alerts in Xcode 11
  • Index(es):
    • Date
    • Thread