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 07-10-2010, 06:17 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 1
cquark is on a distinguished road
Default UITextField 'editing changed' event handling

Dear guys

What I'm trying to do:
1. check input text in a UITextField control.
2. if the input text is not in a correct form, correct it and reassign it to the UITextField.

The problem is:
when I assigned a new text into the UITextField in the 'editing changed' event handler, a new 'editing changed' event occurs and the event handler gets called infinite times.

My question is:
What is the proper way to achieve what I want?

Thanks in advance
cquark is offline   Reply With Quote
Old 01-14-2011, 03:39 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 2
onlybasit is on a distinguished road
Talking UITextFieldDelegate

Quote:
Originally Posted by cquark View Post
Dear guys

What I'm trying to do:
1. check input text in a UITextField control.
2. if the input text is not in a correct form, correct it and reassign it to the UITextField.

The problem is:
when I assigned a new text into the UITextField in the 'editing changed' event handler, a new 'editing changed' event occurs and the event handler gets called infinite times.

My question is:
What is the proper way to achieve what I want?

Thanks in advance
You might have solved the problem by now. But for future visitors you can accomplish this task by using the UITextFieldDelegate.

Use the delegate method
Code:
textField:shouldChangeCharactersInRange:replacementString:
to allow or disallow text changes.

For the above case we can do,

Code:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

	NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];

	if( /* newString is not in correct form */ ) {
		NSString *fixedString = @"fixed string";
		textField.text = fixedString;
		return NO;
	}

	return YES;
}
onlybasit is offline   Reply With Quote
Reply

Bookmarks

Tags
editing changed, event, uitextfield

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: 328
14 members and 314 guests
akphyo, alexP, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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