Nav Link On

iPhone Dev Forums > General Development > SDK Coding Help > Displaying Text With Button

Reply

 

LinkBack Thread Tools Display Modes
Old 11-12-2008, 02:03 AM   #1 (permalink)
Junior Member
Default Avatar
 
Join Date: Nov 2008
Posts: 4
Default Displaying Text With Button

Hi, I'm trying to make an iPhone app that displays text when you press a button. I'm using this code:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

[display setStringValue:@"Hello World"];
However, when I run it the app freezes, with the button down not allowing me to exit the app.

I'm assuming that code may only be Cocoa and not Cocoa Touch. Can someone let me know what code I should use?
Thanks in advance.
Nickel is offline   Reply With Quote
Old 11-12-2008, 09:22 AM   #2 (permalink)
Member
Default Avatar
 
Join Date: Oct 2008
Posts: 31
Default

Hi Nickel,
Any iPhone app has an UIView at it's base, the UIView does not have the property to display text it does not know how to.
Instead use an UILabel/UITextViewController anything with a text property to add on your UIView.
And when you press the button you should tell your label/controller to display the text.

Regards,
Sergiu.
sergiu.burlacu is offline   Reply With Quote
Old 11-12-2008, 09:23 AM   #3 (permalink)
Junior Member
Default Avatar
 
Join Date: Oct 2008
Posts: 14
Default

Is a bit less to tell you more. Is it exactly this line of code, or can you tell us in which context you call this line?
Diskordia is offline   Reply With Quote
Old 11-12-2008, 07:08 PM   #4 (permalink)
Junior Member
Default Avatar
 
Join Date: Nov 2008
Posts: 4
Default

Thanks for the response. So I made a UILabelController.
Do I keep the display outlet in my main or put it in Label Controller?
What do I connect the display outlet to?
Is this code right?:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

[display setStringValue:@"Hello World"];
Or what should I change.

Thanks.

Last edited by Nickel; 11-12-2008 at 07:40 PM.
Nickel is offline   Reply With Quote
Old 11-14-2008, 11:52 AM   #5 (permalink)
Junior Member
Default Avatar
 
Join Date: Oct 2008
Posts: 14
Default

Quote:
Originally Posted by Nickel View Post
Thanks for the response. So I made a UILabelController.
Do I keep the display outlet in my main or put it in Label Controller?
What do I connect the display outlet to?
Is this code right?:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

[display setStringValue:@"Hello World"];
Or what should I change.

Thanks.
I guess you have an UILabel outlet
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

IBOutlet UILabel display;
and you connected it in the IB with the label.
Than you defineed an IBAction
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

 - (IBAction)buttonPressed:(id)sender;
and also connect it in the IB with the button.

If you have not done that, you can set the text in the display variable as often as you want, it will not have any effect!
If you did everything right, you have an implementation of the IBAction which might look like following:
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

- (IBAction)buttonPressed:(id)sender {
    display.text = @"Hello World";
}
Diskordia is offline   Reply With Quote
Reply

iPhone Dev Forums > General Development > SDK Coding Help


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


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC1