我创建了一个UITableViewCell类,在其中我创建了一个将UIScrollView作为其contentView来构建的单元格。
UIScrollView工作正常并具有水平滚动功能,但是这可以防止UITableViewCell类的触摸方法工作。
这就是我将UIScrollView添加到UITableViewCell
的方法- (void)drawCell
{
nameString = [[UILabel alloc] init];
nameString.backgroundColor = [UIColor clearColor];
nameString.frame = CGRectMake(15.0, 0.5, 70.0, 40.0);
nameString.text = [itemsDictionary objectForKey:@"Name"];
addressString = [[UILabel alloc] init];
addressString.backgroundColor = [UIColor clearColor];
addressString.frame = CGRectMake(105.0, 0.5, 95.0, 40.0);
addressString.text = [itemsDictionary objectForKey:@"Address"];
rd4String = [[UILabel alloc] init];
rd4String.backgroundColor = [UIColor clearColor];
rd4String.frame = CGRectMake(220.0, 10.5, rd4String.frame.size.width, 50.0);
rd4String.text = [NSString stringWithFormat:@"ID %@: %@",[itemsDictionary objectForKey:@"name"] ,[itemsDictionary objectForKey:@"address"]];
[rd4String sizeToFit];
scrollCell = [[UIScrollView alloc] init];
scrollCell.backgroundColor = [UIColor whiteColor];
scrollCell.frame = CGRectMake(0.0, 0.0, ScreenWidth, 45.0);
[scrollCell setContentSize:(CGSizeMake((220.0 + rd4String.frame.size.width)+15, 45.0))];
[scrollCell addSubview:nameString];
[scrollCell addSubview:addressString];
[scrollCell addSubview:rd4String];
[[self contentView] addSubview:scrollCell];
}
我从UITableViewCell调用这个类,一切都正常显示,我可以滚动UITableViewcell,我就是无法选择单元格。
答案 0 :(得分:1)
虽然缺少问题的整体详细说明,但您可以检查一下是否正确使用UITableViewDelegate
并实施了tableView:didSelectRowAtIndexPath:
方法。
此外,如果您想在表格单元格中实施滑动操作,您可以参考其中一个实现: