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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-16-2008, 09:53 PM   #1 (permalink)
mking
Registered Member
 
Join Date: Nov 2008
Posts: 28
Default code works on simulator and not device

I have written some code that will parse a text field and replace it with only the numeric values that were typed in. For example if the user types in: 200,000 I will parse it and set the value in the field to 200000. The code works perfectly in the simulator, but on the device it fails. When I debug on the device I can see that the if statement in the code never gets triggered. This is very strange because it will get triggered on the simulator. I have supplied the code below in case it helps. Please let me know if you have any recommendations.

Code:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	[theTextField resignFirstResponder];
	
	//fix any non-numeric numbers
	NSString *temp  =nil;
	NSString *new_string = nil, *one_char = nil, *testp = nil, *test0 = nil, *test1 = nil, *test2 = nil, *test3 = nil, *test4 = nil, *test5 = nil, *test6 = nil, *test7 = nil, *test8 = nil, *test9 = nil;
	testp = [[NSString alloc] initWithFormat:@"."];
	test0 = [[NSString alloc] initWithFormat:@"0"];
	test1 = [[NSString alloc] initWithFormat:@"1"];
	test2 = [[NSString alloc] initWithFormat:@"2"];
	test3 = [[NSString alloc] initWithFormat:@"3"];
	test4 = [[NSString alloc] initWithFormat:@"4"];
	test5 = [[NSString alloc] initWithFormat:@"5"];
	test6 = [[NSString alloc] initWithFormat:@"6"];
	test7 = [[NSString alloc] initWithFormat:@"7"];
	test8 = [[NSString alloc] initWithFormat:@"8"];
	test9 = [[NSString alloc] initWithFormat:@"9"];
	int string_length;
	
	//new_string seems to be using the same address as one_char and new_stirng isn't being updated in the if statement
	temp = [[NSString alloc] initWithFormat:@"%@", theTextField.text];
	new_string = [[NSString alloc] initWithFormat:@""];
	string_length = [temp length];
	one_char = [[NSString alloc] initWithFormat:@""];
	for(int i = 0; i < string_length; i=i+1)
	{
		one_char = [temp substringWithRange: NSMakeRange(i, 1)];
		if (one_char == testp || one_char == test0 || one_char == test1 || one_char == test2 || one_char == test3 || one_char == test4 || one_char == test5 || one_char == test6 || one_char == test7 || one_char == test8 || one_char == test9)
		{
			new_string = [new_string stringByAppendingString:one_char];
		}
	}
	theTextField.text = new_string;
        return YES;
}
mking is offline   Reply With Quote
 

» Advertisements
» Online Users: 743
18 members and 725 guests
anshuk1219, Domele, gascertificate, her-ur, Inupgames, iphone.savvy, jimmie6loa, kampftrinker, mapiko, nidie, oceanlablight, ratheesh, soonw29, srishtimehta, superblooddrainer, Yuvaraj.M, zbynda
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,825
Threads: 89,207
Posts: 380,637
Top Poster: BrianSlick (7,129)
Welcome to our newest member, srishtimehta
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.