gpt4 book ai didi

iphone - 如何为uiTableView中的每个单元格设置不同的图像?

转载 作者:行者123 更新时间:2023-12-01 19:11:06 24 4
gpt4 key购买 nike

我有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];
}

预期产量:

我得到的输出:

最佳答案

UITableViewCell方法填充tableView:willDisplayCell:forRowAtIndexPath:内容。并使用NSString方法比较2个isEqualToString:

编辑:

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
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++)
{
NSString* session_type = [[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_type"];
if([seesion_type isEqualToString: @"workshop"])
cell.imageView.image = [UIImage imageNamed:@"workshops.png"];
else if([session_type isEqualToString: @"keynote"])
cell.imageView.image = [UIImage imageNamed:@"keynote.png"];
else if([session_type isEqualToString: @"panel"]|| [[[appDelegate.serverResponseArray objectAtIndex:i]valueForKey:@"session_topic" ] isEqualToString: @"WISNET"])
cell.imageView.image = [UIImage imageNamed:@"pannel.png"];
else if([session_type isEqualToString: @"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];
}

关于iphone - 如何为uiTableView中的每个单元格设置不同的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com