如果不在第一个文本字段中输入值,则不将光标传递到下一个文本字段

时间:2014-02-03 07:26:48

标签: ios objective-c uitableview uitextfield

我在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;
                            }
                        }
                    }
                }
            }
        }
    }
}];

1 个答案:

答案 0 :(得分:0)

而不是在尝试编辑另一个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;

}

我希望这会有所帮助。