Created
June 24, 2013 14:27
-
-
Save 0xMarK/5850441 to your computer and use it in GitHub Desktop.
Form fields stepper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) viewWillAppear:(BOOL)animated { | |
UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; | |
toolbar.barStyle = UIBarStyleBlackTranslucent; | |
toolbar.items = [NSArray arrayWithObjects: | |
[[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previous:)], | |
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], | |
[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:self action:@selector(next:)], | |
nil]; | |
[toolbar sizeToFit]; | |
for (UIView * view in self.view.subviews) { | |
if ([view isKindOfClass:[UITextField class]]) { | |
UITextField * txt = (UITextField *)view; | |
txt.inputAccessoryView = toolbar; | |
txt.returnKeyType = UIReturnKeyDone; | |
} | |
} | |
[super viewWillAppear:animated]; | |
} | |
- (void)next:(id)sender { | |
NSInteger nextTag = currentFirstResponder.tag + 1; | |
UIResponder* nextResponder = [currentFirstResponder.superview viewWithTag:nextTag]; | |
if (nil != nextResponder && [nextResponder isKindOfClass:[UITextField class]]) { | |
[nextResponder becomeFirstResponder]; | |
} else { | |
[currentFirstResponder resignFirstResponder]; | |
} | |
} | |
- (void)previous:(id)sender { | |
NSInteger nextTag = currentFirstResponder.tag - 1; | |
UIResponder* previousResponder = [currentFirstResponder.superview viewWithTag:nextTag]; | |
if (nil != previousResponder && [previousResponder isKindOfClass:[UITextField class]]) { | |
[previousResponder becomeFirstResponder]; | |
} else { | |
[currentFirstResponder resignFirstResponder]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment