我有 tableView,我想根据特定条件为 tableView 中的每个单元格设置不同的图像,但我得到了所有单元格最后满足条件的图像。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.textLabel.numberOfLines = 2;
if (self.pickerSelectedRow == [self.datePickerArray objectAtIndex:1])
{
for (int i=0; i<[appDelegate.serverResponseArray count]; i++)
{
if([[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_type" ] isEqual: @"workshop"])
{
cell.imageView.image = [UIImage imageNamed:@"workshops.png"];
}
if([[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_type" ] isEqual: @"keynote"])
{
cell.imageView.image = [UIImage imageNamed:@"keynote.png"];
}
if([[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_type" ] isEqual: @"panel"]|| [[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_topic" ] isEqual: @"WISNET"])
{
cell.imageView.image = [UIImage imageNamed:@"pannel.png"];
}
if([[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_type" ] isEqual: @"social"] || [[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_topic" ] isEqual: @"RWW"])
{
cell.imageView.image = [UIImage imageNamed:@"social.png"];
}
}
cell.textLabel.text = [[self.globalSessionArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
}
预期输出:
我得到的输出: