Iphone 将UIImageView或UIView添加到分组表的单元格中
我在iPhone上分组表的单元格上设置UIImageView或UIView时遇到问题 为此,我使用此代码Iphone 将UIImageView或UIView添加到分组表的单元格中,iphone,objective-c,Iphone,Objective C,我在iPhone上分组表的单元格上设置UIImageView或UIView时遇到问题 为此,我使用此代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; NSArray *listData
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sotreKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row ==1)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 14, 40, 40)];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"Back.png",nil]];
[cell.contentView addSubview:imageView];
[imageView release];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
但它并没有放在电池上。当我选择只显示该时间的行时,有什么问题
有人知道问题出在哪里吗。我认为图像被单元格覆盖了
提前谢谢我确实对可能发生的事情有一些想法 将图像视图添加到contentView,然后设置textLabel的文本,该文本是contentView的一部分,可能位于图像顶部。试试这个,看看你是否至少能看到左边的图像
cell.imageView.image = [UIImage imageNamed:@"Back.png"];
现在,当您将单元格出列时,您需要记住上次创建单元格时添加的所有视图仍然存在,因此当您滚动时,您只需将按钮堆叠在彼此的顶部即可
还有下面一行[tableView取消RowatineXpath:indexPath:YES];是死代码,因为它发生在return语句之后。您可能希望将其放在委托调用中–tableView:willDisplayCell:ForRowatineXpath:尝试创建
cell.accessoryType = UITableViewCellAccessoryNone;
似乎您正在附件视图中添加图像
如果是,则可以添加cell.accessoryView=imageView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sotreKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row ==1)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 14, 40, 40)];
imageView.image = [UIImage imageNamed:@"Back.png"];
[cell.contentView addSubview:imageView];
[imageView release];
}
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
return cell;
}
请确保您的图像名为Back.png而不是Back.png,因为手机上的iOS对密钥敏感 仔细检查Back.png是否确实存在于项目资源中。因此,请使用[imageView setBackgroundColor:[UIColor redColor];它实际上会帮助您查看图像是否由于单元格/表格背景而不可见color@joe你知道在我的应用程序中已将表格视图分组的单元格中添加图像时出现了什么问题吗。@imran是的,我的应用程序中有图像app@imran否[imageView setBackgroundColor:[UIColor redColor]];不工作我的朋友accessoryType默认为none,但这是正确的。Ajay可以将imageView设置为accessoryView。