[英]indexPath.row not giving correct value in tableView custom cell iOS
我做了定制的cell
與scrollView
的右側cell
和imageView
在左邊。 現在,當我點擊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;
}
UIScrollView *scrollView = (UIScrollView *)[cell viewWithTag:16];
用以下內容更改上面的行。
UIScrollView *scrollView = (UIScrollView *)[cell viewWithTag:indexPath.row];
我希望這對你有用。
您應該查看以下文檔參考: 響應者鏈
基本上,您的事件不會沿着響應者鏈上升,因為滾動視圖可以捕獲它。 我不知道您要達到什么目的,但是將scrollview包含在scrollview中(因為表從本質上來說就是scrollview)是一個壞主意,而且確實很難實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.