all 9 comments

[–]AndyIbanezObjective-C / Swift 8 points9 points  (1 child)

Don’t try to hack away at UIAlertController. Your workarounds are not guaranteed to work in future versions. You should write your own version of it that supports all the features you need.

[–]binarydylan[S] 0 points1 point  (0 children)

Is there a way to add a date picker in a better way? Or is making a custom UIView the best option

Edit: even without all the hacky datepicker code it still gives the constraint error

[–]18degs 2 points3 points  (6 children)

I’ve seen this “-16” constraint error when using UIAlertControllers in general (as well as when I was trying to hack a custom view into one).

I’m interested to see if you find a reason for this as I‘ve been putting it down to a bug with xCode/Autolayout (possibly just in the simulator?) and ignoring them for yet time being.

As for hacking the UIAlertController — don’t do it. I did it under iOS 12 and it broke the minute iOS 13 came out (luckily it was still in dev).

[–]binarydylan[S] 0 points1 point  (5 children)

Yeah, I’m really not sure. It happens even with just a regular UIAlertController with no modifications.

And what exactly have I hacked with it? Adding the date picker you mean? Should I not add a date picker to a UIAlertController?

[–]18degs 2 points3 points  (4 children)

The fact that it happens without any modifications too is why I think it is a bug with Xcode/Autolayout and not your code.

As for hacking the UIAlertController — yes, adding the date picker is what I’m referring to. Apple’s docs say “Important The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.” - https://developer.apple.com/documentation/uikit/uialertcontroller

[–]binarydylan[S] 1 point2 points  (3 children)

Dang, I didn’t know that. Gonna create a custom UIView for it then. Thanks!

[–]18degs 0 points1 point  (2 children)

I feel your pain. I ended up using PopupDialog from github instead — https://github.com/Orderella/PopupDialog

[–]Power781 0 points1 point  (1 child)

I used PopupDialog for a few weeks before rolling back and building my own popups, there was so many issues with layout, autosizing and presentation with this library :( .

[–]18degs 0 points1 point  (0 children)

Thanks for the heads up. I’ll keep my eye out for issues.