1

現在、スクロールビューとテーブルビューを持つアプリを作成しています。http://johansorensen.com/articles/touches-and-uiscrollview-inside-a-uitableview.htmlのようなコードを使用しました が、スクロールビューとテーブルビューの組み合わせにより、didSelectrow 関数が機能しなくなりました。

助けてくれてありがとう!

注意してください: 明確に答えてください。私は最も経験豊富な iOS 開発者ではありません。

4

1 に答える 1

1

あなたの場合はあなたのをUIScrollView隠すのでcell、あなたはそのためのセルに触れることができません。UITableViewそのためのdidSelectRowAtIndexPath方法は機能しません。

リンクから次のコードを記述して追加scrollViewします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;
}

その後、

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

それはあなたに役立つかもしれません。

于 2013-01-26T16:34:11.997 に答える