我正在使用
样式中的UITableViewCell对象UITableViewCellStyleSubtitle(即左侧的图像视图,粗体的文本标签以及详细文本标签下的文本标签)来创建我的表格.现在我需要检测触摸UIImageView并且还要知道单击图像视图的索引路径/单元格.我试过用
cell.textLabel.text = @"Sometext";
NSString *path = [[NSBundle mainBundle] pathForResource:@"emptystar1" ofType:@"png"];
UIImage *theImage = [UIImage imageWithContentsOfFile:path];
cell.imageView.image = theImage;
cell.imageView.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.每当点击图像时,都会didSelectRowAtIndexPath:被调用.我不想创建一个单独的UITableViewCell并添加自定义按钮.有没有办法检测UIImageView自己的触摸?
我从这里使用CollapsibleTableView并根据我的要求修改它以实现可折叠部分。这是它现在的样子。
由于根据 UI 设计,我的部分有一个边框,因此我选择了部分标题作为我的 UI 元素,在折叠和展开模式下都保存数据。
原因:我尝试过但无法在下面解释的这个模型中工作 -
** 在部分标题中包含我的标题元素,并在其单元格中包含每个项目的详细信息。默认情况下,该部分处于折叠状态。当用户点击标题时,单元格被切换显示。正如我所说,由于需要向整个部分(点击的标题及其单元格)显示一个边框,因此我选择了部分标题作为我的 UI 操作元素。这是我的 tableView 代码 -
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections.count
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.row {
case 0:
return sections[indexPath.section].collapsed! ? 0 : (100.0 + heightOfLabel2!)
case 1:
return 0
case 2:
return 0
default:
return 0
}
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header …Run Code Online (Sandbox Code Playgroud)