这是我的代码,
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if ([cell.textLabel.text isEqualToString:@"Small" ]) {
cell.imageView.image=nil;
cell.accessoryView = nil;
cell.accessoryType=UITableViewCellAccessoryCheckmark;
return cell;
}但是复选标记正在添加到单元格的右角,我想将其添加到单元格内的另一个位置,如下所示,
[[chkmrk alloc]initWithFrame:CGRectMake(200, -4, 100, 50)];发布于 2013-09-11 17:51:08
尝试以下代码。实际上,accessory View是单元格中的按钮。创建一个自定义单元格,并在该单元格内部使用-layoutSubviews方法定位CustomCell.m文件中的AccessoryView布局。代码如下:
- (void) layoutSubviews
{
[super layoutSubviews];
UIView * arrowView = nil;
for (UIView* subview in self.subviews)
{
if ([subview isKindOfClass: [UIButton class]])
{
arrowView = subview;
break;
}
}
CGRect arrowViewFrame = arrowView.frame;
arrowViewFrame = CGRectMake(200, -4, 100, 50);
arrowView.frame = arrowViewFrame;
}这肯定会对你有所帮助。
发布于 2013-09-11 16:52:40
你可以修改它--但更安全的方法是只添加带有所需图像的新子视图。
[cell.contentView addSubview:yourAccesorView];你可以通过设置frame.origin.x,y来控制它的位置
发布于 2013-09-11 16:53:06
不可以更改UITableViewCell的accessoryView的位置。您需要自定义您的单元格。
例如在cell.contentView中添加按钮,将图像(选中/取消选中图像)放在按钮上,并通过按钮tag在其点击事件上对其进行管理(选中或取消选中)。
https://stackoverflow.com/questions/18736630
复制相似问题