我将 UIToolBar 添加到我的 UITextField 使用:
- (void)viewDidLoad {
[super viewDidLoad];
self.email.delegate = self;
self.password.delegate = self;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
UIBarButtonItem* previous = [[UIBarButtonItem alloc] initWithTitle:@"Anterior" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
UIBarButtonItem* next = [[UIBarButtonItem alloc] initWithTitle:@"Próximo" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:nil action:nil];
UIBarButtonItem* ok = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(ok:)];
[toolbar setItems:[[NSArray alloc] initWithObjects:previous, next, space, ok, nil]];
[toolbar setTranslucent:YES];
[toolbar setTintColor:[UIColor blackColor]];
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UITextField class]]) {
[(UITextField*)view setInputAccessoryView:toolbar];
}
}
}
现在我将 UIScrollView 添加到我的 UIViewController 并且我的 UIToolBar 不再显示。我错过了什么?我想我将工具栏添加到视图而不是滚动视图,并且因为滚动视图位于视图上方,所以我看不到工具栏。我该如何解决?我需要添加到滚动视图以将内容移动到键盘后面。