Reputation: 171
At the moment I'm creating an app which has a scrollview and tableview. I used the code like here: http://johansorensen.com/articles/touches-and-uiscrollview-inside-a-uitableview.html but cause of the combination of the scrollview and tableview the didSelectrow function doesn't work anymore.
Thanks for helping!
Please notice: answer clear, I'm not the most experienced iOS developer.
Upvotes: 1
Views: 822
Reputation: 47099
In your case UIScrollView
hide your cell
, so you can not touch cell of UITableView
therefor didSelectRowAtIndexPath
method is not work.
Write following code form your link for add scrollView
with in UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ScrollCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 25, 320, 25)];
scroller.showsHorizontalScrollIndicator = NO;
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320*4, 25)];
contentLabel.backgroundColor = [UIColor clearColor];
contentLabel.textColor = [UIColor whiteColor];
NSMutableString *str = [[NSMutableString alloc] init];
for (NSUInteger i = 0; i < 100; i++) { [str appendFormat:@"%i ", i]; }
contentLabel.text = str;
[scroller addSubview:contentLabel];
scroller.contentSize = contentLabel.frame.size;
[cell addSubview:scroller];
}
return cell;
}
and then use
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
It may be useful for you.
Upvotes: 1