skyylex
skyylex

Reputation: 815

Special symbols not work in UIAlertView

I have some problem with new line adding in UIAlertView. Category.rusname is NSString, containing "\n" symbols, smth like that "Phone1\n, Phone2]n". But instead of adding newline in the "\n" location alertView display string with "\n" symbol. And the string is displaying without nessesary new lines. There is the code.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: category.rusname message:[NSString stringWithFormat:@"%@", category.message] delegate:nil cancelButtonTitle:@"Ок" otherButtonTitles: nil];
[alert show];
return;

enter image description here

Upvotes: 1

Views: 524

Answers (2)

Mike Weller
Mike Weller

Reputation: 45598

UIAlertView will not convert "\n" substrings ('\' + 'n' in the input) into new lines. The only place this usually happens is when Localizable.strings is parsed (or built as a binary plist at compile time).

If category.message wasn't loaded from a strings file, you will need to perform this conversion yourself, or just use real newlines in the first place.

Upvotes: 3

Brian Slick
Brian Slick

Reputation: 31

On the assumption that category.message is already a string, then there is no reason to use stringWithFormat:@"%@". Just do message: category.message.

Upvotes: -1

Related Questions