【问题标题】:Do not pass cursor to next textfield without entering value in first textfield不要将光标传递到下一个文本字段而不在第一个文本字段中输入值
【发布时间】:2014-02-03 07:26:47
【问题描述】:

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


[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;
                            }
                        }
                    }
                }
            }
        }
    }
}];

【问题讨论】:

  • 我已经在 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  • 谁能推荐我
  • 你的textFieldShouldBeginEditing:返回什么?,你好像漏掉了,如果可以的话粘贴整个函数
  • 仅出于该目的将光标停留在该文本字段上,仅我使用了 return
  • 我不想让编辑另一个文本字段我必须做的事情

标签: ios objective-c uitableview uitextfield


【解决方案1】:

您在尝试编辑另一个 UITextField 时没有寻找第一响应者,而是尝试了另一种方法:不允许 UITextField 辞去第一响应者的职务。这可能是这样的:

 - (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;

}

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2020-03-14
    • 1970-01-01
    • 2021-06-14
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    相关资源
    最近更新 更多