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

View Poll Results: Is this a good question?
Yes 1 50.00%
No 1 50.00%
Its a little empty 0 0%
Voters: 2. You may not vote on this poll

Reply
 
LinkBack Thread Tools Display Modes
Old 08-12-2010, 03:31 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
snrbrn is on a distinguished road
Exclamation Using Variables in an alert box?

I am trying to make an alert box that pops up with a textbox's text as its message, but whenever i try, it never it just pops up with an empty alert.

Here is my code:

Code:
@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
	UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
	[someText show];
	[someText release];
	text = textBox1.text;
	label.text = text;
}
in this case, text is the variable with the textbox's information, but it never shows up. i was thinking maybe NSLog() was the way to fix this problem?
snrbrn is offline   Reply With Quote
Old 08-12-2010, 04:01 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Oh man. I think all noobs should be required to include this poll. I like it.

You aren't using your property correctly. See the link in my signature if you need clarification.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 04:01 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 25
HockeyHippo is on a distinguished road
Default

This is how I would do it:

Code:
-(IBAction)buttonClick{
			NSString *textbox = [NSString stringWithFormat:@"Enter your text here!"];
			UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title!" 
														   message:(@"%@",textbox)
														  delegate:self 
												 cancelButtonTitle:@"Done" 
												 otherButtonTitles:nil];
			[alert show];
			[alert release];
		}
I think that's what you wanted. You can change the text of textbox and it will change the message of the alert.
HockeyHippo is offline   Reply With Quote
Old 08-12-2010, 04:08 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by HockeyHippo View Post
This is how I would do it:

Code:
NSString *textbox = [NSString stringWithFormat:@"Enter your text here!"];
Depends on what the situation is, but since the text is coming from a text field, it is already a string, so the stringWithFormat is unnecessary.

Code:
message:(@"%@",textbox)
If this is even valid code to begin with, you are again taking something that is already a string, and further formatting it again as a string. Unnecessary.

Code:
NSString *someText = [[self theTextField] text];

message:someText
That's all you need.

Or if you don't want the local variable:

Code:
message: [[self theTextField] text]
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 04:35 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 25
HockeyHippo is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post

Code:
message:(@"%@",textbox)
If this is even valid code to begin with, you are again taking something that is already a string, and further formatting it again as a string. Unnecessary.
I think that's right, just using a string formater. I thought thats what he was asking for!

Anyways, my code builds and runs well :S

I guess I'm too noob to answer questions.

/goes home
HockeyHippo is offline   Reply With Quote
Old 08-12-2010, 04:52 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by HockeyHippo View Post
I think that's right, just using a string formater.
Huh. I didn't know that would work just by itself. I assumed it had to be part of NSLog.

If the formatting is appropriate for the situation, that's fine. I just see a lot of people doing initWithFormat or stringWithFormat for plain strings. [...:@"%@", string]. It's already a string, it is still a string, the formatting didn't do anything except make a brand new string that is exactly the same as the old string.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 06:48 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
snrbrn is on a distinguished road
Default

Quote:
Originally Posted by HockeyHippo View Post
This is how I would do it:

Code:
-(IBAction)buttonClick{
			NSString *textbox = [NSString stringWithFormat:@"Enter your text here!"];
			UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title!" 
														   message:(@"%@",textbox)
														  delegate:self 
												 cancelButtonTitle:@"Done" 
												 otherButtonTitles:nil];
			[alert show];
			[alert release];
		}
I think that's what you wanted. You can change the text of textbox and it will change the message of the alert.
But when you declare the NSString *textbox = [NSString stringWithFormat:@"Enter text here!"]; wouldnt that just put "Enter text here" in the alert box?
snrbrn is offline   Reply With Quote
Reply

Bookmarks

Tags
alertviews, strings, textfields

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: 353
5 members and 348 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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