Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-06-2010, 12:53 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 99
cpcdev is on a distinguished road
Default How to add line breaks in Text View

Hi,

I added a simple text view object to one of my views and I'm having trouble adding line breaks. Basically, I want to put space in between each of the paragraphs in the text view but when I hit enter on my keyboard, instead of going to the next line it takes me out of the editing mode. I'm running a hackintosh so I don't have the same return key as mac users.. is this why? Thanks for the help
cpcdev is offline   Reply With Quote
Old 08-06-2010, 01:31 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

I don't know how you can add it via interface builder but what I usually do is just make it an IBOutlet then add this on the viewDidLoad.

Code:
textView.text = [NSString stringWithFormat:@"Line 1\nLine 2\nLine 3\n"];
This would show as:

Line 1
Line 2
Line 3

Essentially, \n is a line break.
Speed is offline   Reply With Quote
Old 08-06-2010, 01:32 AM   #3 (permalink)
r_l
Registered Member
 
Join Date: Jul 2010
Posts: 19
r_l is on a distinguished road
Default

Quote:
Originally Posted by cpcdev View Post
Hi,

I added a simple text view object to one of my views and I'm having trouble adding line breaks. Basically, I want to put space in between each of the paragraphs in the text view but when I hit enter on my keyboard, instead of going to the next line it takes me out of the editing mode. I'm running a hackintosh so I don't have the same return key as mac users.. is this why? Thanks for the help
Try with return key on simulator/device keyboard, if it is working fine, then u need not bother about inputs from desktop keyboard.
r_l is offline   Reply With Quote
Old 08-06-2010, 02:42 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 99
cpcdev is on a distinguished road
Default

Quote:
Originally Posted by Speed View Post
I don't know how you can add it via interface builder but what I usually do is just make it an IBOutlet then add this on the viewDidLoad.

Code:
textView.text = [NSString stringWithFormat:@"Line 1\nLine 2\nLine 3\n"];
This would show as:

Line 1
Line 2
Line 3

Essentially, \n is a line break.
Thanks, I tried this and I get the app to build and launch successfully but when I click on the tab bar item to load the view it crashes and I get this error in console:

"'NSUnknownKeyException', reason: '[<UIViewController 0x5b594a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textview.'"

Here's what I added in the .h file:

Code:
IBOutlet UITextView *textview;

@property (nonatomic, retain) UITextView *textview;
for the .m file:

Code:
@synthesize textview;
void view did load method:

Code:
	
textview.text=[NSString stringWithFormat:@"Hi how are you \n good how are you? \n great, thanks\n"];
Then I created a XIB file for this, added a text view object to the XIB, then linked up the text view with the IBOutlet and the view with the view in the document folder.

What am I doing wrong? Thanks for your help
cpcdev is offline   Reply With Quote
Old 08-06-2010, 11:36 AM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

I just tested it and it worked fine >.< Try remove the properties for the IBOutlet? Here is how I have mine setup and working:

.h
Code:
IBOutlet UITextView *textView;
.m
Code:
-(void)viewDidLoad {
	
	textView.text = [NSString stringWithFormat:@"Hello\nHi\nHow are you?"];
	
}
I don't have the properties in mine, try it without them? You can try this in a new view controller to get the hang of it without the tab-bar then implement it with the tab bar.
Speed is offline   Reply With Quote
Old 08-07-2010, 07:18 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 99
cpcdev is on a distinguished road
Default

Quote:
Originally Posted by Speed View Post
I just tested it and it worked fine >.< Try remove the properties for the IBOutlet? Here is how I have mine setup and working:

.h
Code:
IBOutlet UITextView *textView;
.m
Code:
-(void)viewDidLoad {
	
	textView.text = [NSString stringWithFormat:@"Hello\nHi\nHow are you?"];
	
}
I don't have the properties in mine, try it without them? You can try this in a new view controller to get the hang of it without the tab-bar then implement it with the tab bar.

Ok great, I got it to work. It was actually a problem with my tab bar item not being wired up to the controller class.

How can I add bold font to the text or change the color in this case?

Thnx again
cpcdev is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 306
11 members and 295 guests
alexP, arash5500, gordo26, HemiMG, linkmx, mediaspree, nobstudio, Objective Zero, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0