我正在尝试设置键盘工具栏上的下一个/上一个按钮,我想要放入导航以转到下一个/上一个文本字段。这是我正在尝试的。
如何使用系统栏按钮项目更改为文本字段?
-(void)addTeam{
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(15, (0+(50*[teamsArray count])), 273, 50)];
[view setTag:[teamsArray count]+1];
UILabel *lblTeamName = [[UILabel alloc ] initWithFrame:CGRectMake(5,0,58,20)];
[lblTeamName setBackgroundColor:[UIColor clearColor]];
lblTeamName.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(12.0)];
lblTeamName.text = [NSString stringWithFormat:@"Team %i",[teamsArray count]+1];
[lblTeamName setTag:7];
[view addSubview:lblTeamName];
UITextField* txtTeamName = [[UITextField alloc]initWithFrame:CGRectMake(5,20,150,30)];
[txtTeamName setBorderStyle:UITextBorderStyleRoundedRect];
[txtTeamName setPlaceholder:@"Team Name"];
[txtTeamName addTarget:self action:@selector(hideKeyboard) forControlEvents:UIControlEventEditingDidEndOnExit];
[txtTeamName setDelegate:self];
[view addSubview:txtTeamName];
UIButton *btnDelete = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnDelete addTarget:self
action:@selector(btnDelete_OnTouch:)
forControlEvents:UIControlEventTouchDown];
[btnDelete setTag:[teamsArray count]];
[btnDelete setTitle:@"-" forState:UIControlStateNormal];
btnDelete.frame = CGRectMake(160, 20, 20, 30);
[view addSubview:btnDelete];
[scrollView addSubview:view];
[teamsArray addObject:view];
}
-(BOOL)textFieldShouldBeginEditing: (UITextField *)textField
{
UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
keyboardToolBar.barStyle = UIBarStyleDefault;
[keyboardToolBar setItems: [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],
[[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
nil]];
textField.inputAccessoryView = keyboardToolBar;
}
- (void)nextTextField {
????
}
-(void)previousTextField
{
????
}
答案 0 :(得分:0)
你可以使用下一个和上一个按钮, How to navigate through textfields (Next / Done Buttons)
在ViewDidLoad中执行此操作
UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
keyboardToolBar.barStyle = UIBarStyleDefault;
[keyboardToolBar setItems: [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],
[[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
nil]];
textField.inputAccessoryView = keyboardToolBar;