1

UITableViewCell 内に UIPageControl を備えた UIScrollView を含めて(選択可能な画像のリストを)水平方向にスクロールできるという多くの情報源を見てきましたが、私が望むことを行う生の例が見つかりません。スクロールビューが「機能」しましたが、先に進む方法がわかりません.誰かが私にガイダンスを送ってくれることを願っています.

cellForRowAtIndexPath 内でセルを作成し、scrollView と pageControl の両方をサブビューとして追加します。

UITableViewCell *cell = [self.challengeListView dequeueReusableCellWithIdentifier:SubmitChallengeCellIdentifier];
    if(cell == nil){
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SubmitChallengeCellIdentifier] autorelease];
        cell.frame = CGRectMake(0, 0, 1000, 50);
    }   

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 50)];
    [scrollView setContentSize:CGSizeMake(1000, 50)];
    [[cell contentView] addSubview:scrollView];

    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
    [pageControl setNumberOfPages:4];
    [[cell contentView] addSubview:pageControl];

表示されているもののスクリーンショットを添付しました

なにか

メイン ビューの下部は、scrollView/pageControl を含む UITableView であり (これを示す scrollerIndicator が表示されるので、水平方向にスクロールします)、そのメソッドを次のように設定しました。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{   
    return 1;
}   

私の Scroll ビューは「 horizo​​ntalScroller 」を示し、前後にスクロールできますが、明らかにそこにはコンテンツがありませんたとえば、「クリック可能な」画像のリストを tableView/scrollView に入力するにはどうすればよいですか? どんな方向性でも大歓迎です - できれば「この男が似たようなことをしたので、このリンクをチェックしてください」ではなく、この機能を正しく実装する方法についての説明が必要です (特に iOS 3.0+ に関して- それは私のAppleがこれを実装することで私たちの生活を楽にしたことを理解する)

4

1 に答える 1

1

I've solved my own problem; maybe the reason no once answered me is because its a minor implementation once you understand each view's purpose.

From within cellForRowAtIndexPath: I created a standard UITableViewCell, however I altered the frame of the cell to my own custom frame of 1000 width by 50 height (catered to my needs for project).

I then created a UIScrollView, set it to the following (keep in mind I have my tableView defined in IB, so I'm mapping some of my height/widths to those values):

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];

I then create the desired image view (I realize I will next create a loop that does many images and lays them out across the scroll view):

UIImage *image = [UIImage imageNamed:@"dummy.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 80, 78);
[scrollView addSubview: imageView];

Here's the part I was missing. After adding the scrollView to the cell contents, you need to use the UIPageControl (which didn't seem obvious to me for this implementation at first) to setup the actual "visual horizonal scrolling" affect:

   [[cell contentView] addSubview:scrollView];

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
[pageControl setNumberOfPages:4];
[[cell contentView] addSubview:pageControl];

Hope that helps someone's search - I spent quite some time on Google looking for the example I just explained and didn't have much luck other than the general overview of how it would work.

于 2011-02-23T18:37:05.517 に答える