[英]Add Subview at single Index in Custom UITableViewCell?
is it possible to implement a subview (like an image) at only one row of a UITableViewCell? 是否可以在UITableViewCell的仅一行上实现子视图(如图像)? I'm having an extra class for my Cell.
我的单元格要上一堂课。 At the moment I call the function with [tblcell addimage];
目前,我使用[tblcell addimage]调用了该函数; but it only adds the image at the last cell.
但只会将图片添加到最后一个单元格。 Is it possible to add the image at indexPath.row?
是否可以在indexPath.row上添加图像? If yes, how?
如果是,怎么办? (I know, that I need to do: [tblcell addimageatIndex:indexPath.row];, that's not the problem, how can I insert the subview at indexPath.row?)
(我知道,我需要做:[tblcell addimageatIndex:indexPath.row] ;,这不是问题,如何在indexPath.row插入子视图?)
If it helps: I have a nib for the cell. 如果有帮助:我的牢房有一个笔尖。
Thanks for answers! 感谢您的回答!
You can do something like this: 您可以执行以下操作:
UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
[cell.contentView addSubview:myImageView];
//You will probably need to tweak a bit your UIImageView, so:
myImageView.frame=CGRectMake(value1,value2,value3,value4);//being value* floats
Basically you are adding an UIImageView
into your cell.contentView
. 基本上,您是将
UIImageView
添加到cell.contentView
。
Depending on the case, its nice to create a custom UITableViewCell, if you think its simpler than adding UIViews to your normal ( UITableViewCell*
) cell. 如果您认为比将UIViews添加到常规(
UITableViewCell*
)单元更简单,则视情况而定,创建自定义UITableViewCell会很不错。 But in your case, you say: 但您的情况是:
at only one row of a UITableViewCell
在UITableViewCell的仅一行
Only one. 只有一个。 So I ask you, is it worth to edit your custom cell just for one?
因此,我问您,仅需编辑一个自定义单元格值得吗? Well, its up to you, but I would probably just add the subView I want into the contentView.
好吧,这取决于您,但是我可能只是将我想要的subView添加到contentView中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.