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 10-16-2010, 02:23 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
ShayansMind is on a distinguished road
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Angry UITextField HELP...simple

Someone please help me on this, its 12 AM and I still can't figure this out....
I have a textfield and a label...when ever I type something in the field.text automatically changes to "Carolyn"

*Is there a way to allow both "if" statements to work?

Code:
 -(IBAction)analyze:(id)sender {

	if ([textField.text length] >= 2) {
		
		int  text = rand() % 3;
		switch (text) {
			case 0:
				chill.text = @"Your so chill" ;
				break;
			case 1:
				chill.text = @"you wishh" ;
				break;
			case 2:
				chill.text = @"haha, not even" ;
				break;
				
			default:
				break;	
		}
	} 
	else {
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Please input your name" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	if (textField.text = @"Carolyn") {
	
		chill.text = @"Carolyn, pretty darn chill; duuuhhh";
}
}
ShayansMind is offline   Reply With Quote
Old 10-16-2010, 02:47 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Los Angeles
Posts: 10
baolei is on a distinguished road
Default

1. You have:
if (textField.text = @"Carolyn")
in your code. Did you actually mean:
if (textField.text == @"Carolyn")

Since = will assign @"Carolyn" to textField.text


2. Compared to ==, I guess it's better to use
if([textField.text isEqualToString:@"Carolyn"])



Quote:
Originally Posted by ShayansMind View Post
Someone please help me on this, its 12 AM and I still can't figure this out....
I have a textfield and a label...when ever I type something in the field.text automatically changes to "Carolyn"

*Is there a way to allow both "if" statements to work?

Code:
 -(IBAction)analyze:(id)sender {

	if ([textField.text length] >= 2) {
		
		int  text = rand() % 3;
		switch (text) {
			case 0:
				chill.text = @"Your so chill" ;
				break;
			case 1:
				chill.text = @"you wishh" ;
				break;
			case 2:
				chill.text = @"haha, not even" ;
				break;
				
			default:
				break;	
		}
	} 
	else {
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Please input your name" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	if (textField.text = @"Carolyn") {
	
		chill.text = @"Carolyn, pretty darn chill; duuuhhh";
}
}
__________________
My App:
Calculation Automator (Free App)
baolei is offline   Reply With Quote
Old 10-16-2010, 03:38 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

exactly

if(x=y)
return always true, because you are doing an assigment (and if not fail return true).

if(x==y)
depend on what are x and y, a NSString is an object, and have it's particolaur method to compare, so use [x isEqualToString:y] as baolei said.
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
elsestatment, field, ifstatment, rand, text

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: 338
8 members and 330 guests
Desert Diva, dre, hain, HemiMG, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
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 01:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0