我已经设置了一个包含两个字段的视图控制器。我在键盘上方实现了一个工具栏,其中包含上一个和下一个按钮。
我有一个字段列表的数组。
// Setup array of listed fields
textFields = [[NSArray alloc] initWithObjects:usernameField,passwordField, nil];
工具栏
(id)initWithTextField:(UITextField*)textField
{
self = [super initWithFrame:CGRectMake(0, 250, 320, 40)];
if (self) {
inputToolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
doneButton= [[UIBarButtonItem alloc]
initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self
action:@selector(performdone:)];
nextButton= [[UIBarButtonItem alloc]
initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextButtonMethod:)];
nextButton.tintColor = [UIColor blackColor];
previousButton= [[UIBarButtonItem alloc]
initWithTitle:@"Previous"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(previousButtonMethod:)];
previousButton.tintColor = [UIColor blackColor];
inputToolBar.barStyle=UIBarStyleDefault;
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[inputToolBar setItems:[NSArray arrayWithObjects:previousButton,nextButton,flexSpace,doneButton,Nil] animated:NO];
[self addSubview:inputToolBar];
}
return self;
}
现场调用工具栏:
[self.usernameField setInputAccessoryView:myInputAccessoryView];
我想知道在我的 nextButtonMethod 和 previousButtonMethod 方法中添加什么以使光标转到数组列表中的下一个字段。我怎样才能做到这一点?