UITextField inside UITableViewCell will not be the first responder

I have a strange problem with my application. After I read all the questions about almost the same problem, I still could not find something to solve my problem. I am using UITableViewController to display KoreanFood details. The first cell is a custom UITableViewCell (OverviewCell) with an image and two UITextFields that I created and placed in the Storyboard (AutoLayout). Looks like this

https://dl.dropboxusercontent.com/u/28177144/Screen%20Shot%202013-05-29%20at%2023.39.46.png (sorry, I can’t insert a picture, but I don’t have a reputation yet 10)

I have subclassed UITableviewCell as follows:

OverviewCell.h @interface OverviewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UITextField *englishTitleTF; @property (strong, nonatomic) IBOutlet UITextField *koreanTitleTF; @property (strong, nonatomic) IBOutlet UIImageView *myImageView; @property (strong, nonatomic) UIImage *thumbnail; 

My text fields on the Storyboard are set to enable / UserInteractionenabled, and the delegate is my TVC. When I create cells, I also do this in code:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == GENERAL_SECTION) { static NSString *overviewCellID = @"overviewCell"; OverviewCell *overviewCell = [tableView dequeueReusableCellWithIdentifier:overviewCellID forIndexPath:indexPath]; overviewCell.englishTitleTF.text = self.generalInfo.titleEnglish; overviewCell.koreanTitleTF.text = self.generalInfo.titleKorean; overviewCell.englishTitleTF.enabled = YES; overviewCell.koreanTitleTF.enabled = NO; //BOOL test = [overviewCell.englishTitleTF becomeFirstResponder]; overviewCell.koreanTitleTF.delegate = self; overviewCell.englishTitleTF.delegate = self; UIImageView *imageView = [[UIImageView alloc] initWithImage:self.generalInfo.thumbnail]; overviewCell.myImageView = imageView; overviewCell.myImageView.frame = CGRectMake(25, 25, 95, 95); [overviewCell addSubview:overviewCell.myImageView]; return overviewCell; } 

The comment is with BOOL NO, and I just don’t know why ... When I set the text and displayed it correctly, I know that the Outlets are installed and Cell is not zero (I checked this), Why is this not the first responder? I also tried some suggestions in the OverviewCell subclass, for example, a success test or the implementation of the setSelected: / setEditing: methods. But startFirstResponder for textField doesn't change anything here either.

ANY HELP would be greatly appreciated, I desperately ask for it.

+4
source share
1 answer

A view cannot become the first responder until it is added to the chain of respondents, which happens automatically when the view is added as a subview of the view, which is in the window in the list of windows of the application object. In other words, your cell has not yet been added to the table view, so it is not related to anything and therefore cannot be the first responder.

Try sending becomeFirstResponder from a method that is called after the table view has finished loading its cells. And of course, do not do this:

 overviewCell.koreanTitleTF.enabled = NO; 
+4
source

Source: https://habr.com/ru/post/1483472/


All Articles