pivotallabs.com
15 Oct '12, 12am
UITextField and Blocks:
If you've ever used a UITextField in an iPhone project (or, I suppose, an NSTextField in a Cocoa project) you know that you pass it a delegate object in order to respond to events. Handling the "Return" key press from the on-screen keyboard may look something like this (probably implemented in your view controller): - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (0 == [textField.text length]) { return NO; } [self doSomethingWithText:textField.text]; [textField resignFirstResponder]; return YES; } The delegate pattern is de rigueur for Cocoa classes, so you've likely never given this much special thought. Unless, that is, you decided at some point to have two text fields on screen at once. With two text fields you need to handle two sets of callbacks. You have a couple options for how to do this: Use the same delegate to handle both sets of callbacks, and use c...
Full article:
http://pivotallabs.com/users/adam/blog/articles/1353-ipho...