简体   繁体   中英

First Responder not Changing

Currently i have this tableview in my storyboard i have this structure in my table 在此处输入图片说明 在此处输入图片说明

i already have placed to each textfield a tag 0 - 6 and i have this piece of code

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if(textField.returnKeyType == UIReturnKeyNext) {
        NSInteger nextTag = textField.tag + 1;
        UIResponder* nextResponder = [textField viewWithTag:nextTag];
        [nextResponder becomeFirstResponder];

    } else if (textField.returnKeyType == UIReturnKeyDone) {
        [textField resignFirstResponder];
    }
    return YES;
}

but for some reason it doesn't change to next textfield any ideas on what am i doing wrong?

According to the documentation , the viewWithTag: 's return value is:

Return Value

The view in the receiver's hierarchy whose tag property matches the value in the tag parameter.

It seems unlikely that your textField is the parent view of some other text field. You should probably call this on your table view or the view controller's view property.

You can try resigning the old first responder first:

[textField resignFirstResponder];
[nextResponder becomeFirstResponder];

Sometimes it is a bit tricky, if this does not work you can try just if the [textField resignFirstResponder]; works... If it works and it is the [nextResponder becomeFirstResponder]; that does not work you can always try it with a delay: [nextResponder performSelector:@selector(becomeFirstResponder) afterDelay:0.1];

Hope it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM