![](/img/trans.png)
[英]UITableViewCell accessoryView overlap custom button of cell OR how to change accessoryView position?
[英]Changing a custom accessoryView in a uitableviewcell?
我试图在用户单击单元格后立即更改uitableviewcell的自定义配件视图。 我该怎么做?
作为记录,我正在使用Matt Gallagher的自定义表格视图教程:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
下载源链接: http : //projectswithlove.com/projects/EasyCustomTable.zip
编辑
尝试了此代码,但仅在修饰后更改了附件。 还尝试了willSelectRowAtIndexPath具有相同的结果。
- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
return indexPath;
}
编辑
通过使单元格的背景图像包含附件解决了问题。 因此,通过使其成为图像的一部分来“伪造”附件
也许您可以尝试在willSelectRowAtIndexPath / didSelectRowAtIndexPath中重新加载单元格:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:NO];
}
另一个建议:didSelectRowAtIndexPath 返回void而不是NSIndexPath。
您可以按如下所示的选择方法更改附件视图:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = newView;
}
这只是获取当前选择的单元格,然后更改其附件视图。 您的视图对象将放在newView所在的位置。
使用UIImageView的HighlightedImage属性:
UIImageView* arrowView = [[UIImageView alloc] initWithImage:normalImage];
arrowView.highlightedImage = selectedImage;
cell.accessoryView = arrowView;
[arrowView release];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.