【发布时间】:2016-05-18 09:15:24
【问题描述】:
我的应用程序中有一个正在加载 xml 菜单的表。我在其中为每个单元格放置了一个 uiimageview 作为项目符号图像。但我的问题是第一个时间表显示正确(一个单元格中的一个图像)但是当我在菜单中进一步向下滚动时。它开始在一个单元格中显示图像 3 次。我将发布我的代码。
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"menuCell";
UITableViewCell *cell = (UITableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-bold" size:18];
if ([[[rssOutputData objectAtIndex:indexPath.row]xmlid] isEqualToString:@"1"]) {
cell.textLabel.textColor = [UIColor redColor];
[cell setIndentationLevel:3];
[cell setIndentationWidth:10];
cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(5,cell.frame.size.height/2+5, 15, 15)];
}else if ([[[rssOutputData objectAtIndex:indexPath.row]xmlid] isEqualToString:@"2"]) {
cell.textLabel.textColor = [UIColor blueColor];
[cell setIndentationLevel:6];
[cell setIndentationWidth:10];
cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(35,cell.frame.size.height/2+5, 13, 13)];
}else if ([[[rssOutputData objectAtIndex:indexPath.row]xmlid] isEqualToString:@"3"]) {
cell.textLabel.textColor = [UIColor lightGrayColor];
[cell setIndentationLevel:9];
[cell setIndentationWidth:10];
cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(65,cell.frame.size.height/2+5, 11, 11)];
}
cell.textLabel.text = [[rssOutputData objectAtIndex:indexPath.row]xmltitle];
cellImage.image=[UIImage imageNamed:@"arrow.png"];
[cell addSubview:cellImage];
return cell;
}
【问题讨论】:
-
只需在
cell == nil中添加imageView 并为图像视图设置tag值。他们使用viewWithTab:获取图像视图,然后设置图像视图 -
你试过我下面的答案了吗
-
是的,我确实试过了,它停止了箭头的重复,但现在图像没有显示它应该显示的位置我的意思是它的框架不正确,因为我想要我在 if ([[[rssOutputData objectAtIndex :indexPath.row]xmlid] isEqualToString:@"1"]) {
-
什么是
xmlid?以及为什么要设置不同的indentation level和indentation width?
标签: ios objective-c xcode uitableview uiimageview