Search code examples
iosuitableviewuitextfieldfirst-responder

Error when making UITextField subView a first responder in UITableView


I am trying to create a UITableView in which you create a new item by pulling the whole table down. Similar to Clear app http://www.realmacsoftware.com/clear/.

I am adding a UITextField

addingTaskTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, NEW_ITEM_HEADER_HEIGHT)];
addingTaskTextField.hidden = YES; // I unhide it for editing 

[addingTaskView addSubview: addingTaskTextField];
[self.tableView addSubview: addingTaskView];

I get this error

"setting the first responder view of the table but we don't know its type (cell/header/footer)"

when trying to make the textField a first responder.

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:   (BOOL)decelerate {
    if (scrollView.contentOffset.y < -NEW_ITEM_HEADER_HEIGHT) {
        self.tableView.contentInset = UIEdgeInsetsMake(NEW_ITEM_HEADER_HEIGHT, 0, 0, 0);
        addingTaskTextField.hidden = NO
        [addingTaskTextField becomeFirstResponder];  <-- Trouble Line
    }
}

I am running Xcode 4.3.1 developing for iOS 5 with ARC and storyboard.

Similar posts:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/85516-error-when-setting-uitextfield-first-responder.html"

Setting the inputAccessoryView of a UITextField to its superview


Solution

  • I know that this is an old post but in my attempt to fix the same issue I kept running into this question. After finding the "solution" I decided to come back here and answer it, in case anyone else ends up in my situation (always bumping up against this exact question.)

    In the dev center an Apple engineer responds to a similar question with:

    You can safely ignore that.

    So there you have it! And although this posting has to do with UICollectionViews I figured UITableVews would fall into the same category.