I have different texts in my custom cells in my UITableView, each text has a category. according to category a certain image is assigned to UIImageView in my CustomCell like that:
– (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;
}
still doesn’t work… any ideas? thanks!
the problem is your string equality check…this categoryForPicture==@”Анекдоты” will return true only if the two are the same object, which will never be the case here, you want to us NSStrings isEqualToString: in order to accomplish your goal… so
hope that helps