In this iPhone SDK example, we are going to discuss about becomeFirstResponder that belongs to UIResponder class. In simple words UIResponder is a responders for objects that respond to and handle events. Where as "becomeFirstResponder" is an instance method of it that notifies the receiver about it's status of becoming the first responder in its window.
Also remember that in case of two responders, responder object will act as in case of current responder resign from being the first responder status. In this example we are discussing about the same condition. In the example we have two text field and we wants the second text field to act as fist responder in case of first text field is left blank.
Basically, in this application we are comparing two variables for certain condition and for the comparison we can use isEqualToString(for NSString) and isEqualToNumber(for NSNumber). The given example will check if the first text field is blank or not. If the first text field is blank that means it is satisfying the condition and and the second text field will become first responder.
See the given line of code...
if ([txtField.text isEqualToString:@""]) [txtField2 becomeFirstResponder];
Posted on: August 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles