【问题标题】:didSelectrow doesn't work with scrollview and tableview (iOS)didSelectrow 不适用于滚动视图和表格视图(iOS)
【发布时间】:2013-01-26 16:22:48
【问题描述】:

目前我正在创建一个具有滚动视图和表格视图的应用程序。 我在这里使用了这样的代码:http://johansorensen.com/articles/touches-and-uiscrollview-inside-a-uitableview.html 但是由于滚动视图和表格视图的组合,didSelectrow 函数不再起作用。

感谢您的帮助!

请注意:回答清楚,我不是最有经验的 iOS 开发者。

【问题讨论】:

    标签: iphone objective-c uitableview uiscrollview didselectrowatindexpath


    【解决方案1】:

    在您的情况下UIScrollView 隐藏您的cell,因此您不能触摸UITableView 的单元格,因此didSelectRowAtIndexPath 方法不起作用。

    在您的链接中编写以下代码以在UITableView 中添加scrollView

    - (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;
    }
    

    然后使用

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    }
    

    它可能对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多