【发布时间】:2011-09-19 15:33:00
【问题描述】:
我的 UITableView 的自定义单元格中有不同的文本,每个文本都有一个类别。根据类别,在我的 CustomCell 中将某个图像分配给 UIImageView,如下所示: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CCell";
// Dequeue or create a cell of the appropriate type.
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Configure the cell.
cell.primaryLabel.text = [self.arrayWithTextsFromSelectedCategory objectAtIndex: indexPath.row];
NSString *keyForText=[self.arrayWithTextsFromSelectedCategory objectAtIndex:indexPath.row];
categoryForPicture=[dicWithTitlesAsKeysAndCategoriesAsValues objectForKey:keyForText];
//cell.categoryImg=[dicWithTitlesAsKeysAndCategoriesAsValues objectForKey:keyForText];
NSLog(@"Current category!!! %@", categoryForPicture);
NSLog(@" %@ ", keyForText);
//NSString *textToExtract;
//textToExtract=[self.texts objectForKey:keyForText];
cell.secondaryLabel.text=[self.texts objectForKey:keyForText];
if (categoryForPicture==@"Стихи")
{
NSLog(@"Assigning proper image!!");
cell.iconImage.image=[UIImage imageNamed:@"stixi.png"];
}
if (categoryForPicture==@"Анекдоты")
{
NSLog(@"Assigning proper image!!");
cell.iconImage.image=[UIImage imageNamed:@"jokes.png"];
}
else
{
cell.iconImage.image=[UIImage imageNamed:@"stand_icon.png"];
}
//cell.imageView.image=[UIImage imageNamed:@"cell.png"];
//cell.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell.png"]]];
return cell;
} 仍然不起作用...有什么想法吗?谢谢!
【问题讨论】:
标签: iphone objective-c uitableview