私は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];
}
期待される出力:
私が得ている出力: