不要将光标传递到下一个文本字段而不在第一个文本字段中输入值

不要将光标传递到下一个文本字段而不在第一个文本字段中输入值

本文介绍了不要将光标传递到下一个文本字段而不在第一个文本字段中输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableView 中动态创建了文本字段我不想在没有在第一个文本字段中输入值的情况下传递光标

I have created textfields dynamically in UITableView I don't want to pass cursor without entering value in first textfield

[self.playerTable.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,BOOL*stop)
 {
     UITableViewCell *cell = obj;

     if([cell isKindOfClass:[UITableViewCell class]])
     {
         for(UITextField *textField in cell.contentView.subviews)
         {
             if([textField isKindOfClass:[UITextField class]])
             {
                 if ([textField isFirstResponder])
                 {
                     [textField resignFirstResponder];

                     isEditMode = NO;
                     if(!isEditMode && [playerstr length] > 0)
                     {

                         NSMutableArray *playerinfoArry = [dbWrapper getPlayerInfo];
                         for (Playerinfo *player in playerinfoArry)
                         {
                             if ([player.playername isEqualToString:playerstr])
                             {
                                 isPlayerExist = YES;
                                 isEditMode = !isEditMode;
                                 CustomAlert *alert = [[CustomAlert alloc] initWithTitle:@"" message:@"Please choose a different name" delegate:nil cancelButtonTitle:nil otherButtonTitle:@""];
                                 [_nameField resignFirstResponder];
                                 [alert showInView:self.view];
                                 NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:selectedRow inSection:0];

                                 [_playerTable selectRowAtIndexPath:indexPath1 animated:YES  scrollPosition:UITableViewScrollPositionTop];
                                 return;
                            }
                        }
                    }
                }
            }
        }
    }
}];

推荐答案

与其在尝试编辑另一个 UITextField 时寻找第一响应者,您是否尝试过另一种方法:不允许 UITextField 辞去第一响应者的职务.这可能类似于:

instead of looking for the first responder while trying to edit another UITextField, have you tried the other approach: not permitting the UITextField to resign as first responder. This could be something like:

 - (BOOL) textFieldShouldEndEditing:(UITextField *)textField{

        for(UITextField *otherTextField in self.view)
        {
            if ([otherTextField isKindOfClass:[UITextField class]] && [textField.text isEqualToString:otherTextField.text]){
                CustomAlert *alert = [[CustomAlert alloc] initWithTitle:@"" message:@"Please choose a different name" delegate:nil cancelButtonTitle:nil otherButtonTitle:@""];
                [alert showInView:self.view];
                return NO;
            }
        }
    return YES;

}

我希望这会有所帮助.

这篇关于不要将光标传递到下一个文本字段而不在第一个文本字段中输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:22