UITextField成为FirstResponder不显示文本的光标

休克·恩伯克(HurkNburkS)

我在每个UITableViewRow上都有两个UITextField,并且由于某些原因,当我在UIKeyboard上按回车键时,两个特定的UITextField都不会重新组合起来(光标不可见)。

我有一个正在使用的自定义UITableViewCell,如果愿意,可以向您显示此代码,但是我不认为这是问题所在,因为返回键可用于95%的UITableViewCells。所以我在想,也许这就是我如何处理UITextFields的委托方法?

这是我用于委托方法的代码。

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textfield {

        int height = self.finishingTableView.frame.size.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];
    // 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:@"mMM"]]) {
            tempUpdatedRow = @"T";
            // remove kevalues
            [tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
            [tempFinishingObjectDictionary removeObjectForKey:@"new_mMM"];
            // update keyvalues
            [tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
            [tempFinishingObjectDictionary setValue:textField.text forKey:@"new_mMM"];
        }
    } else {
        if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"hMM"]]) {
            tempUpdatedRow = @"T";
            // remove kevalues
            [tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
            [tempFinishingObjectDictionary removeObjectForKey:@"new_hMM"];
            // update keyvalues
            [tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
            [tempFinishingObjectDictionary setValue:textField.text forKey:@"new_hMM"];
        }
    }
    NSLog(@"%@", tempFinishingObjectDictionary);
    [coreDataController editSelectedFinishing:htmlProjID UpdatedNSD:tempFinishingObjectDictionary SelectedRow:selectedItemIndexPathRow];
    [SVProgressHUD dismiss];


    NSLog(@"%@", selectedItemDictionary);

    return YES;
}

我不知道在哪里寻找或如何找到此错误,因为它看起来是如此随机,但每次都在相同的UITextField上发生。

我认为上面的代码可能是问题所在。但是,在记录了所有内容并调试了几个小时之后,我开始认为这是UITableViewCells中的UITextFields的错误。

雷蒙德·布莱恩(Raymond Brion)

[[self.view viewWithTag:textField.tag+1] canBecomeFirstResponder] == YES

您还需UITextField要先辞职,然后再将下一个设置为第一响应者

[textField resignFirstResponder];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

inputAccessoryView中的UITextField不会成为FirstResponder

来自分类Dev

UITextField不显示NSFontAttributes

来自分类Dev

引导表单不显示光标

来自分类Dev

成为FirstResponder非常慢

来自分类Dev

UITextField / UITextView / UISearchBar上的死锁/硬冻结成为FirstResponder

来自分类Dev

删除数据后,UITableView单元格中的UITextField无法成为FirstResponder

来自分类Dev

UITextField成为firstResponder在单元格之间传输值和属性

来自分类Dev

UITextField如何调用viewDidAppear中的成为firstResponder来减慢当前动画的播放速度?

来自分类Dev

在Richtextbox中追加文本时不显示C#光标/插入符

来自分类Dev

UITextView不显示文本

来自分类Dev

AutoCompleteTextView不显示文本

来自分类Dev

TabLayout不显示文本

来自分类Dev

AutoCompleteTextView不显示文本

来自分类Dev

TextRenderer不显示文本

来自分类Dev

Pygame不显示文本

来自分类Dev

TextView 不显示文本

来自分类Dev

setTimeout 不显示文本

来自分类Dev

画布不显示文本

来自分类Dev

AlertDialog 不显示文本

来自分类Dev

MessagingStyle 不显示文本

来自分类Dev

文本块不显示

来自分类Dev

UITextfield在编辑时不显示内容

来自分类Dev

从presentMoviePlayerViewControllerAnimated关闭后,UITextfield不显示键盘

来自分类Dev

UITextfield在编辑时不显示内容

来自分类Dev

Java不显示菜单文本

来自分类Dev

UItextView不显示长文本

来自分类Dev

SearchView不显示queryHint文本

来自分类Dev

Android菜单不显示文本

来自分类Dev

小卵石不显示文本