3

I am not sure if this is the culprit but the biggest change I did to this project was upgrading to Swift 4 a couple of days ago. I know that my UIAlertController messages were showing multiline when needed but today I realized by chance that all of them became single line and has ellipsis at the end. Since I show these messages from an API, I cannot use "\n". The code is simple enough;

let alert = UIAlertController(title: "Title", message: "Long message that must be shown as multiline", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
    alert.dismiss(animated: true, completion: nil)
}))
present(alert, animated: true, completion: nil)

I checked some other related questions but none of them worked for me. This one was asked as the same problem recently but did not get an answer, and has a hacky workaround posted as a solution;

All the alert dialog message and textField have been changed to single line. Please checkout the image

Any advice on what to check is really appreciated.

Batuhan C.
  • 384
  • 3
  • 10
  • I just tested it on Xcode and I have no issues. So my question is what is the API you're using? – Jake Feb 25 '18 at 21:02
  • @Jake The API is my own developed API which I also use in the Android app. When I print the JSON string of the response, the whole message is there. And as I said, I am pretty sure this was working a while ago so something must have broken it. Did you try it with Swift 4? – Batuhan C. Feb 25 '18 at 21:24
  • Yes I am. I printed on 3 or 4 lines in the alerts message. – Jake Feb 25 '18 at 21:43
  • So if you're pulling the message from your api, what type of data is being placed in the message? Have you tried to force cast it as `String`? – Jake Feb 25 '18 at 21:50
  • @Jake The response is JSON and the message is a string. It is not related to the API because I tried to manually type the message in the code and it is still one line. – Batuhan C. Feb 25 '18 at 23:01
  • What version of Xcode are you running? – Jake Feb 25 '18 at 23:03
  • @Jake Xcode 9.2 (9C40b) – Batuhan C. Feb 26 '18 at 10:10
  • I'm using the same. – Jake Feb 26 '18 at 14:17
  • In order to try and assist please update your code to display what is in your project exactly. – Jake Feb 26 '18 at 14:21
  • @Jake Sorry I could not share any more code because it's part of a very large customer project but I managed to locate the problem. Thank you for following up with me. – Batuhan C. Feb 28 '18 at 09:52

1 Answers1

8

Do not know why the downvotes but I have found the issue after 3 days of pulling my hair out. There was a UILabel extension in one of the 3rd party Pods I have been using. Its code was marked as "Locked" so I think that's why it did not show up in the search results before. I had to download the source codes for all of the pods from their repositories and searched inside. It was overriding these functions and properties of the default UILabel, instead of creating its own UILabel subclass;

override open func draw(_ rect: CGRect) {}
override open var intrinsicContentSize: CGSize {}

Since the UIAlertViewController uses UILabel to display the message, I have tried to comment out these lines and my issue went away. If anyone having the same issue, search for UILabel extensions in your code AND in your embedded libraries source codes.

Batuhan C.
  • 384
  • 3
  • 10