【发布时间】:2013-12-29 07:03:48
【问题描述】:
我在cell 的右侧和左侧的imageView 上使用scrollView 自定义cell。现在,当我单击imageView 时,我得到了indexPath.row 的正确值,但是当我单击scrollView indexPath.row 时,返回的是最后一个单击图像的值。有什么建议可以解决这个问题吗?
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *hlCellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:hlCellID];
if(cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hlCellID];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UIScrollView *scrollView = (UIScrollView *)[cell viewWithTag:16];
scrollView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width,scrollView.frame.size.height);
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];
int i=0;
for(i=0;i<15;i++){
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0+i*100, 0, 100, 100)];
label.text = @"HELLO";
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:@"ArialMT" size:18];
[scrollView addSubview:label];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width+i*label.frame.size.width,scrolView.frame.size.height);
}
return cell;
}
【问题讨论】:
-
请显示识别单元格的滚动视图代码。
-
请分享代码
-
我在 cellForRowAtIndexPath 方法中添加了设置滚动视图的代码。
-
如果您有自定义单元格,请创建自定义类并将您的滚动视图和图像视图作为属性连接!这将为您省去很多麻烦。
-
请在您收到错误值的地方添加您的代码(即您的 didSelect 方法)。您的其他代码无关紧要
标签: ios iphone ipad uitableview uiscrollview