views:

277

answers:

4

Hi

I have a UITextView that takes an NSString with formating stringWithUTF8String. It is getting its values from a database and I want the text in the database to be rendered with breaks within the text. I tried using "\n" to do this but it gets rendered as text. Doing this in my information page of the app as straight text worked but I think the reason its not working when taking it from the database is because of the formating.

Any suggestions?

Appreciate your time!

A: 

You're saving a literal "\n" in the database. Try saving a newline.

tc.
A: 

Set the (UIKeyboardType)keyboardType and (UIReturnKeyTYpe) returnKeyType

if you are building in code.

If you are using IB then just go to the first inspector panel and set the TextInputTraits

Vivek Sharma
A: 

Just as a sanity check, this is a TextView and not a TextField, correct?

Oldmicah
A: 

Expanding tc's answer a bit: when you have newlines in the string, you probably want to convert them to \n (that is, @"\\n" in Cocoa) then save to the db and, on getting the string BACK from the db, you probably want to convert those back to newlines. So you'd use code something like this:

NSString *saveString = [myTextField.text stringByReplacingOccurancesOfString: @"\n" withString: @"\\n"];
// save it to the db
// ... later ...
NSString *dbString = // get the db from the db.
myTextField.text = [dbString stringByReplacingOccurancesOfString: @"\\n" withString: @"\n"];
Olie