У меня есть простой UIViewController с UINavigationController.Все, что содержит контроллер представления, является единственным UITextField.Это представление имеет две цели:
- Создать новый элемент.В этом случае в UINavigationController есть кнопки «Отмена» и «Сохранить».
- Редактирование имени существующего элемента.В этом случае в верхнем левом углу есть только кнопка «Назад».
Мне бы хотелось, чтобы клавиша Return на клавиатуре iPhone отклоняла UITextField.
Вот мой код textFieldShouldReturn:
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if(self.navigationItem.rightBarButtonItem) {
//If we're creating a new item (there'd be a Save button in the top right)
[self saveItem]; //This method just saves the Core Data for this item.
[self.delegate addItemViewController:self didAddItem:item]; //This works fine; this method just tells the delegate to dismiss this view controller.
}else {
//If there's no button in the top-right corner, then we're editing an existing fridge.
[self saveItem]; //This method just saves the Core Data for this item.
[self.navigationController popViewControllerAnimated:YES]; //This is what doesn't work.
}
[textField resignFirstResponder];
return YES;
}