我有一个自定义UITableViewCells的UITableView,每个都有两个UITextFields。当我在打开的视图中选择一个UITextField,即不滚动时,在打开的视图中选择一个UITextField。它成为FirstReasponder,我可以输入文本,因为我打开在打开的视图中输入所有UITextFields可以成为FirstReasponder,但是当我到达该开放视图的UITableViewCells的末尾,并尝试加载当前不可见的下一个UITableViewCell并将其设置为UITextField成为第一个应答者dosnt的工作。UItextField becomeFirstReasponder返回否
我在textFieldShouldReturn中设置了一个if语句,它确认textField返回NO成为FirstReasponder。
我想知道如何解决这个问题,我一直在这个问题上停留了一段时间,并寻找解决方案,但还没有找到符合我的情况的任何东西。下面是我使用的UITextFieldDelegates,因为我认为在这里我应该做一些像调用或加载下一个UITableViewCell的东西,但我不知道如何。
#pragma mark - Textfield Delegates
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
if ([textField isEqual:cell.widthTexField]) {
nWidth = [[sortedItemsArray objectAtIndex:textField.tag] valueForKey:@"w_MM"];
} else if ([textField isEqual:cell.heightTextField]) {
nHeight = [[sortedItemsArray objectAtIndex:textField.tag] valueForKey:@"h_MM"];
}
return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField*)textfield {
int height = self.finishingTableView.frame.size.height;
NSLog(@"%i", height);
self.finishingTableView.frame= CGRectMake(self.finishingTableView.frame.origin.x, self.finishingTableView.frame.origin.y, self.finishingTableView.frame.size.width, 307);
// select correct row
if (textfield.tag > 999999) {
int adjustTag = textfield.tag-1000000; // remove a million so that you have the text fields correct position in the table. (this is only for height textfields)
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:adjustTag inSection:0];
[finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
return YES;
} else {
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:textfield.tag inSection:0];
[finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
return YES;
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSLog(@"%i", textField.tag+1);
[[self.view viewWithTag:textField.tag+1] becomeFirstResponder];
BOOL success = [[self.view viewWithTag:textField.tag+1] becomeFirstResponder];
if (success) {
NSLog(@"HypnosisView became the first responder");
} else {
NSLog(@"Could not become first responder");
}
// this means there has been a change in the UItextfield
NSLog(@"%@", selectedItemDictionary);
if (textField.tag < 999999) {
tempFinishingObjectDictionary = [selectedItemDictionary mutableCopy];
if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"w_MM"]]) {
tempUpdatedRow = @"T";
// remove kevalues
[tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
[tempFinishingObjectDictionary removeObjectForKey:@"new_w_MM"];
// update keyvalues
[tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
[tempFinishingObjectDictionary setValue:textField.text forKey:@"new_w_MM"];
}
} else {
if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"h_MM"]]) {
tempUpdatedRow = @"T";
// remove kevalues
[tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
[tempFinishingObjectDictionary removeObjectForKey:@"new_h_MM"];
// update keyvalues
[tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
[tempFinishingObjectDictionary setValue:textField.text forKey:@"new_h_MM"];
}
}
NSLog(@"%@", tempFinishingObjectDictionary);
[coreDataController editSelectedFinishing:htmlProjID UpdatedNSD:tempFinishingObjectDictionary SelectedRow:selectedItemIndexPathRow];
[SVProgressHUD dismiss];
NSLog(@"%@", selectedItemDictionary);
return YES;
}
任何帮助将超级赞赏,因为我真的坚持这一点。
没关系只是现在执行会让你知道我是如何去的。我在CGPointMake上遇到了一个“问题”,并在修复它之前添加了一个“[”。 – HurkNburkS
由于某种原因,这不是为我滚动。我已经把它放到我的becomeFirstReasponder中,如果在textFieldShouldReturn里面声明,那么如果textfield是NULL,那么我打算执行你给我的代码行。但由于某种原因,它不会为我滚动。我把cellHeight设置为84,所以我会注意到它过多滚动,但它dosnt。 – HurkNburkS