2

Thank you for reading,

I have two UITextFields (along with some labels) inside a UICollectionViewCell. I can select both text fields in the simulator, for iPhone 6, 6+, 5, 5s, 4s, all iOS8.

When I hook up my iPhone, an iPhone 5c iOS7 (not-sim), I can only select the top left portion of the top UITextField. An answer would suggest how to select both text fields, and explore other possible reasons someone wouldn't be able to select text fields, as well as possible de-bug methods for this. For those wondering, I will upgrade to ios8 as soon as I get this app working 100% in ios7.

Solutions I've tried:

  1. Make sure the textField is inside the known superview
  2. Create a new project, get that working correctly, and copy everything as exact as possible
  3. Shifting the Text fields so the bottom one is on top
  4. This had the result of letting me select the new "top" field in the same small hit area.
  5. Selecting the UICollectionView Cell and auto setting the first responder. This does not work as I want the user to choose which field to make first responder.
  6. Set all background elements to a different colour to ensure nothing was overlapping the TextField
  7. Set UICollectionView to be Editable -- it only works with UITableViews
  8. Make sure the collectionview elements are in the right order
  9. Copying and pasting the "Good Text Field" and seeing if that is then selectable.
  10. Deleting the entire ViewController and starting again.
  11. Make sure the UICollectionView cell has "User Interaction Enabled"

My Current set up

  • Heres a screenshot of the storyboard
  • UICollectionView: data-source & delegate = it's superview (UIViewController)
  • UICollectionViewCell: has 4 outlets linking to a custom cell
  • UITextFields: Delegate is set to UIViewController
    • Referencing outlets leading to the Cell
    • EditingDidBegin and EditingDidEnd methods handled in UIViewController
    • One textfield uses a picker input view, the other a keypad

To be clear:

  1. I can get the keyboard to pop up in the simulator, and on my phone in the small hit area
  2. This is not about retrieving the data from text fields.
  3. I could get the test project working but the main project refuses to accept taps in the UITextFields

Relevant Code - UIViewController .m

Interface - Private.m

@interface EnterFinalHRViewController () 
// The current responder showing a keyboard.
@property (nonatomic, assign) id currentResponder;

Text Field Methods

- (IBAction)editingDidBegin:(UITextField *)textField {
self.currentResponder = textField;
}
- (IBAction)resignOnTap:(id)sender {
//called from a single tap on the view, gesture recognizer is present
//called when the text field says "Editing did End"
[self.currentResponder resignFirstResponder];
}

 //implementation of the cell

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath{

static NSString *cellIdentifier = @"swimmerReview";
FinalHeartRateCollectionViewCell *cell = (FinalHeartRateCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; //reuse the cell

Lane *lane = [_lanes objectAtIndex:indexPath.section]; //lanes hold swimmers, so get the lane
Swimmer *swimmer = [lane.swimmers objectAtIndex:indexPath.row]; //swimmers are in the lane, so get the right swimmer

if (swimmer.actualSwimmerName) {
    cell.swimmerFullName.text = swimmer.actualSwimmerName;
} else {
    cell.swimmerFullName.text = @"Assign Swimmer";
}

cell.finalHeartRate.text = @"--";

//Person Picker is a PickerView that lets the user select a swimmer
cell.swimmerFullName.inputView = PersonPicker;

cell.averageStrokeRate.text = [NSString stringWithFormat:@"Avg SR: %.f", swimmer.strokeRateAvg];
cell.AveragePace.text = [@"Avg Pace: " stringByAppendingString: swimmer.setSplitAvg];

return cell;
}

The Question

An answer would suggest how to select both text fields, and explore other possible reasons someone wouldn't be able to select text fields, as well as possible de-bug methods for this.

Quick shout out to all the contributors at SO, you've all been such a resource, and I have read and learned so much from all the questions you have answered. I just couldn't figure it out this time.

Community
  • 1
  • 1

2 Answers2

1

@Ian MacDonald you provided a debug method that led to this gem of a discovery Content View Not Resizing.

My issue was one of running ios7 vs ios8. A simple override of the layout subviews method in my custom cell fixed the issue. A shout out to @Daniel Plamann who you can upvote on the above page for his solution.

//put inside your UICollectionViewCell Custom class

- (void)layoutSubviews
{
  [super layoutSubviews];

  BOOL contentViewIsAutoresized = CGSizeEqualToSize(self.frame.size, self.contentView.frame.size);

  if( !contentViewIsAutoresized) {
    CGRect contentViewFrame = self.contentView.frame;
    contentViewFrame.size = self.frame.size;
    self.contentView.frame = contentViewFrame;
  }
}

The reason my test project worked was because I made it two days ago, and my main project was made 6 months ago before the ios8 launch. So if you find you have done everything correctly, followed the above 10 steps, and you still can't select your subview, here is one more.

Community
  • 1
  • 1
0

It sounds like your cell frame (or one of its superviews) is not large enough. A quick-and-dirty way to debug that would be to add this and the tap the top corner of the textField that you know you can access:

- (IBAction)editingDidBegin:(UITextField *)textField {
  self.currentResponder = textField;
  UIView *superview = textField;
  while (superview != nil) {
    [superview setClipsToBounds:YES];
    superview = [superview superview];
  }
}

It should highlight where you've got framing issues. From there, you can detect exactly which view has the wrong bounds and investigate the auto-layout / regular-layout properties you have set for it.

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
  • You are right. There was a sub view added to the Custom UICollectionViewCell (not by me), which all my interface elements are inside. In my test project the unknown subview re-sizes to the width of the Custom Cell, however in my main project it remains at 50 x 50, clipping that and logging the name showed me. Now to find out why it's added, and how to let it expand to fill the parent view. – Brendan Robertson Oct 30 '14 at 21:09