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 04-21-2010, 11:49 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 12
Unicyclist is on a distinguished road
Default Setting the Label

Hi!

I'm pretty new to cocoa and have a small problem that I hope somebody can help with.

Basically I can't get UILabel to display my "Hello" when I do the following in my ViewDidLoad.

Code:
[oldText initWithString:@"Hello"];
    label.text = oldText;
oldText here is defined as follows

Code:
@interface DisplayViewController : UIViewController {
	UILabel *label;
	NSString *oldText;
}

@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) NSString *oldText;

As a check however, the following does work so everything seems to be connected properly.

Code:
label.text = @"This Works";
I'm guessing its got to do with how I'm defining oldText or some sort of incompatible type? But I'm quite clueless otherwise.

Thanks in advance!
Unicyclist is offline   Reply With Quote
Old 04-21-2010, 12:37 PM   #2 (permalink)
Registered Member
 
finefin's Avatar
 
Join Date: Jun 2009
Posts: 259
finefin is on a distinguished road
Default setText

Code:
[myLabel setText:@"No! *this* should work"];
EDIT: so *this* also works:

Code:
[myLabel setText:[NSString stringWithFormat: @"%@", oldText]];
__________________

I help you, you buy my app - you help me, I buy your app

PARALLAX, The Book Of Sayings - chopped up edition! (HD),omicron,
Canupa Band deluxe (universal), Canupa Band FREE!, Your Face --- follow me on twitter

Last edited by finefin; 04-21-2010 at 12:42 PM.
finefin is offline   Reply With Quote
Old 04-21-2010, 12:40 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 12
Unicyclist is on a distinguished road
Default

Hi finefin!

Thanks for the reply!

That does work. Though, how do I get it to work with my instance oldText?

=)
Unicyclist is offline   Reply With Quote
Old 04-21-2010, 12:42 PM   #4 (permalink)
Registered Member
 
finefin's Avatar
 
Join Date: Jun 2009
Posts: 259
finefin is on a distinguished road
Default

see above
__________________

I help you, you buy my app - you help me, I buy your app

PARALLAX, The Book Of Sayings - chopped up edition! (HD),omicron,
Canupa Band deluxe (universal), Canupa Band FREE!, Your Face --- follow me on twitter
finefin is offline   Reply With Quote
Old 04-21-2010, 12:50 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 12
Unicyclist is on a distinguished road
Default

Thanks finefin!

It seems to be better, the label can now be seen. Though the text defined by oldText doesn't seem to appear.

Instead I get "(null)" appearing in the label.
Unicyclist is offline   Reply With Quote
Old 04-21-2010, 01:03 PM   #6 (permalink)
Registered Member
 
finefin's Avatar
 
Join Date: Jun 2009
Posts: 259
finefin is on a distinguished road
Default

hehe funny.
at this point you could use

Code:
oldText = @"Hello";
__________________

I help you, you buy my app - you help me, I buy your app

PARALLAX, The Book Of Sayings - chopped up edition! (HD),omicron,
Canupa Band deluxe (universal), Canupa Band FREE!, Your Face --- follow me on twitter
finefin is offline   Reply With Quote
Old 04-21-2010, 01:21 PM   #7 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 12
Unicyclist is on a distinguished road
Default

!!!!!!!!!!!!!!!!!

It works!!!!

And I have absolutely no idea why we can do that now!

Could you explain briefly or point me to a resource or something where i could read up on it?

This is totally messing me up... lol
Unicyclist is offline   Reply With Quote
Old 04-21-2010, 01:47 PM   #8 (permalink)
Registered Member
 
finefin's Avatar
 
Join Date: Jun 2009
Posts: 259
finefin is on a distinguished road
Default

the difference is quite simple.

UILabel is a text view, it inherits from UIView.
myLabel.text is an attribute of UILabel (besides font, textcolor, alignment...)
so if you want to set the text attribute of an UILabel, well, you use setText.

oldText is an NSString. it is just a string object. so you can set the string in that easy way.

You use initWithString when you create a new NSString object

Code:
NSString *myString = [[NSString alloc] initWithString:@"Hello"];
EDIT: for more info on the classes you use --> in xcode, mark the class name, right click and select "Find selected text in API reference", take your time and read.
__________________

I help you, you buy my app - you help me, I buy your app

PARALLAX, The Book Of Sayings - chopped up edition! (HD),omicron,
Canupa Band deluxe (universal), Canupa Band FREE!, Your Face --- follow me on twitter

Last edited by finefin; 04-21-2010 at 01:53 PM.
finefin is offline   Reply With Quote
Old 04-21-2010, 01:53 PM   #9 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 12
Unicyclist is on a distinguished road
Default

Thanks for all your help!

=)
Unicyclist is offline   Reply With Quote
Reply

Bookmarks

Tags
nsstring, uilabel

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: 317
20 members and 297 guests
baja_yu, cgokey, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, HowEver, iphonedevshani, jbro, JoeRCruso, mdpauley, n00b, newDev, seokwon lee, SLIC, stanny, Steven.C, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,875
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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