текст в ячейке табличного представления отсутствует при прокрутке вниз - PullRequest
0 голосов
/ 22 октября 2011

Я добавил несколько ячеек в UITableView, и у каждой ячейки есть UITextField, позволяющий пользователям вводить текст.Я также добавил собственный класс ячейки для этого.Я обнаружил, что когда я прокручиваю вниз и возвращаюсь, ввод первых нескольких строк исчезнет.Кто-нибудь знает в чем проблема?

вот кусок моего кода

@implementation MyCell
-(void)setData:(NSString*)str 
{

  UIImage *image = [UIImage imageNamed:@"cellImage copy.png"];
  [[self imageView ]setImage:image];

  lblLocations=[[UILabel alloc]init];
  lblLocations.textAlignment=UITextAlignmentLeft;
  lblLocations.backgroundColor = [UIColor clearColor];
  lblLocations.font = [UIFont boldSystemFontOfSize:12];
   lblLocations.numberOfLines = 2;
  lblLocations.lineBreakMode = UILineBreakModeWordWrap;
  lblLocations.textAlignment = UITextAlignmentCenter;
   lblLocations.text =str ;
  NSLog(@"the title is%@",str);
  [[self contentView]addSubview:lblLocations];
  [lblLocations release];

  txtUnits=[[UITextField alloc]init];
    [txtUnits setAdjustsFontSizeToFitWidth:YES];
  txtUnits.textAlignment = UITextAlignmentCenter;

  txtUnits.returnKeyType = UIReturnKeyDone;
  txtUnits.autocapitalizationType = NO;
  txtUnits.textColor = [UIColor blackColor];
  if ([textDict valueForKey:[NSString stringWithFormat:@"%d",rowNum]]) {
    [txtUnits setText:[textDict valueForKey:[NSString stringWithFormat:@"%d",rowNum]]];
  }
  else
  {
    [txtUnits setPlaceholder:@"0.00"];
  }
  [txtUnits setValue:[UIColor blackColor] 
          forKeyPath:@"_placeholderLabel.textColor"];
  [[self contentView]addSubview:txtUnits];
  txtUnits.backgroundColor = [UIColor clearColor];
  txtUnits.delegate = self;
    [txtUnits release];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
  [textDict setObject:textField.text forKey:[NSString stringWithFormat:@"%d",rowNum]]; 
}

и cellforrow ....

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";


  UITableViewCell *cell=nil;
  if (cell == nil) {
      cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier androw:[indexPath row]] autorelease];
  }
  cell.selectionStyle = UITableViewCellSelectionStyleNone;

  NSMutableDictionary *dict=(NSMutableDictionary*)[locations objectAtIndex:[indexPath section]];

  NSMutableArray *array=(NSMutableArray*)[dict objectForKey:@"locationsArray"];

  MyCell *modelObj=(MyCell*)[array objectAtIndex:indexPath.row];

  NSLog(@"the values of the array are%@",modelObj.title);
  NSString *str = modelObj.title;
  [(MyCell *)cell setData:str];
 return cell;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...