Material-components-ios: [TextFields] Placeholder does not stop floating when text set to nil from dequeued view

Created on 31 Oct 2017  路  15Comments  路  Source: material-components/material-components-ios

When using the MDCTextField in a cell for tableview (added from storyboard) and the textField have some text , the placeholder label position is not coming correctly for MDCTextFields .

I'm attaching a demo project replicating the issue. Here initially the position of the placeholder label is coming correctly but after scrolling down and up we can see the position of the placeholder label is shifted towards top left.

MDCTextFieldTest.zip

Screenshot 1:
simulator screen shot - iphone 7 - 2017-10-31 at 15 25 51

Screenshot 2:
simulator screen shot - iphone 7 - 2017-10-31 at 15 25 59

Version number
31.0.1 & 38.0.1

Needs repro steps Needs actionability review [TextFields] Bug

All 15 comments

Thanks for the issue! I'm guessing this has to be related to the fact that it's dequeued. We can would on better support for that.

Probably related to #2298 .

@jprossardalia Can you verify if this is still an issue? There was some recent work around this area.

@willlarche Yes it is still an issue. I updated the pod to 40.0.2 version and still getting the same problem

Any progress regarding this issues ?

No but I can make it a priority next week.

Hi @willlarche any idea when this will be fixed ?

Work is very busy right now as I/O is two weeks away. I wouldn't expect any completion of this until after then. So May 14+

ok

This issue is still up, is it going to be fixed soon or any work around to fix it temporary ?

Took a stab at this today (see #4391). I can't reproduce. Here's how I'm handling my cells:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextFieldTableViewCellIdentifier];
  if ([cell isKindOfClass:[TextFieldTableViewCell class]]) {
    TextFieldTableViewCell *textFieldCell = (TextFieldTableViewCell*)cell;

    textFieldCell.textField.tag = indexPath.row;
    textFieldCell.textField.delegate = self;

    if (indexPath.row < (NSInteger)self.strings.count) {
      NSString *string = self.strings[indexPath.row];
      textFieldCell.textFieldController.textInput.text = string;
    }
    textFieldCell.textFieldController.placeholderText = [NSString stringWithFormat:@"TextField #%lu", indexPath.row];
  }

  return cell;
}

@jprossardalia , @vikt0r40 , please check how you're handling the text against how I did and write back with what the difference is.

Hi again @willlarche ,

This code did the trick, now it is not reproducing it was my mistake, thank you !

Great! Could you explain what was different?

Hi @willlarche,
I looked through the code and it did the trick. The difference was in my case I was initializing the textFieldController every time when cellForRowAtIndexPath was being called. When I shifted it to awakeFromNib in the cellViewController it fixed the issue.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings