因此,我正在创建一个 UIToolbar 以位于 UIKeyboard 之上,并且完成按钮可以完美运行,直到我调用一个方法来重新加载我的 UITableView。然后除了完成按钮的回调函数(即完成:)之外,一切仍然有效。有人知道为什么会这样吗?我正在使用以下代码使用工具栏创建自定义 UITableView 子类...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section != 1){
if (indexPath.row != 2){
static NSString *CellIdentifier = @"EditableCell";
EditableCell *editableCell = (EditableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (editableCell == nil) {
editableCell = [[EditableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[_myTextField setPlaceholder:@"$0.00"];
[_myTextField setKeyboardType:UIKeyboardTypeDecimalPad];
UIToolbar *toolbar = [[UIToolbar alloc] init];
[toolbar setBarStyle:UIBarStyleBlackTranslucent];
[toolbar sizeToFit];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];
doneButton.title = @"Done";
NSArray *itemsArray = [NSArray arrayWithObjects:doneButton, nil];
[toolbar setItems:itemsArray];
[_myTextField setInputAccessoryView:toolbar];
}
[_myTextField setReturnKeyType:UIReturnKeyNext];
}
else if (indexPath.section == 1){
[_myTextField setPlaceholder:@"Describe this food..."];
[_myTextField setReturnKeyType:UIReturnKeyDone];
}
_myTextField.delegate = self;
return editableCell;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if([text isEqualToString:@"\n"])
[textView resignFirstResponder];
else{
NSMutableString *textFieldString = [[NSMutableString alloc] initWithString:textView.text];
[textFieldString replaceCharactersInRange:range withString:text];
_textViewString = @"";
_textViewString = textFieldString;
_foodDescription = textFieldString;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
return YES;
}