В моем UITableview я получаю странную ошибку. У меня есть массив словарей с именем _cellTextArray, и этот словарь содержит ключи «textLabel», «detailTextLabel» и «cornerLabel». Однако я создал три UILabel's, которые добавляются в contentView ячейки, и их тексту присваивается соответствующее имя в словаре. Моя проблема в том, что textLabels извлекает только первые 5 объектов в словаре и использует их для каждой ячейки, а не извлекает объект по индексу ячейки в словаре.
Пожалуйста, не могли бы вы сказать мне, что я делаю неправильно. Я несколько раз прочесал код, NSLog'ing dictionaryValues для каждого indexPath, и все они верны.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
CheckBox *btn = (CheckBox *)[_checkboxArray objectAtIndex:indexPath.row];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell.contentView addSubview:btn];
//I added this code:
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 3; // 0 means no max.
UIImageView* img = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gradient7.png"]] autorelease];
[cell setBackgroundView:img];
UILabel *lab = [[[UILabel alloc] initWithFrame:CGRectMake(40, 18, cell.contentView.frame.size.width-15, 22)] autorelease];
[lab setText:[[_cellTextArray objectAtIndex:indexPath.row] objectForKey:@"textLabel"]];
[lab setBackgroundColor:[UIColor clearColor]];
[lab setTextColor:[UIColor whiteColor]];
[lab setAdjustsFontSizeToFitWidth:YES];
[lab setTextAlignment:UITextAlignmentLeft];
[cell.contentView addSubview:lab];
UILabel *dlabl = [[[UILabel alloc] initWithFrame:CGRectMake(5, 54, cell.contentView.frame.size.width- 1, 22)] autorelease];
[dlabl setText:[[_cellTextArray objectAtIndex:indexPath.row] objectForKey:@"detailTextLabel"]];
[dlabl setTextColor:[UIColor colorWithRed:1.0 green:0.80 blue:0.0 alpha:1.0]];
[dlabl setBackgroundColor:[UIColor clearColor]];
// [dlabl setAdjustsFontSizeToFitWidth:YES];
[dlabl setTextAlignment:UITextAlignmentLeft];
[dlabl setFont:[UIFont systemFontOfSize:[lab font].pointSize - 3]];
[cell.contentView addSubview:dlabl];
UILabel *cornerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(cell.contentView.frame.size.width - 40, 19, 40, 20)] autorelease];
[cornerLabel setTextColor:[UIColor whiteColor]];
//[cornerLabel setFont:[UIFont systemFontOfSize:12]];
[cornerLabel setAdjustsFontSizeToFitWidth:YES];
[cornerLabel setBackgroundColor:[UIColor clearColor]];
[cornerLabel setTextAlignment:UITextAlignmentCenter];
[cell.contentView addSubview:cornerLabel];
[cornerLabel setAdjustsFontSizeToFitWidth:YES];
[cornerLabel setText:[[_cellTextArray objectAtIndex:indexPath.row] objectForKey:@"cornerLabel"]];
// Adds image to cell
// UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(100, 5, 140, 50)] autorelease];
// [imageView setImage:[UIImage imageNamed:[[_cellTextArray objectAtIndex:indexPath.row] objectForKey:@"image"]]];
// [cell.contentView addSubview:imageView];
}
// Configure the cell.
return cell;
}