2011-07-30 5 views
0

iOS Developer Libraryのサンプルコード、PageControlを使用しています。私が何をしたいかUIScrollView、ボタンのクリックがうまくいかない...

だから、これは私がやったことあるボタンが

2ページに行くをクリックすると

1)MyView.xib
2)にボタンを追加することです。

1)次に、PhoneContentController.mで作成し、以下の方法は、2ページ目に移動するには

- (IBAction)toPageTwo:(id)sender; 

    { 

     NSLog(@"button clicked..."); 
     PhoneContentController * callSview = [[PhoneContentController alloc] init]; 
     [callSview showPage:2]; 

    } 

のように "MyViewController.m" にIBAction作成さMyView.xib
でボタン 2)を作成しました。ボタンがクリックされた場合

[scrollView setContentOffset:CGPointMake(320*(page -1), 0) animated:YES];  

- (void)showPage:(int)page; 

{ 

    [scrollView setContentOffset:CGPointMake(320*(page -1), 0) animated:YES];  
    NSLog(@"Method called..and the scrollview width is %f ", scrollView.frame.size.width); 
    //prints negative value or 0.000. why? 

} 

問題は動作しません。 (PhoneContentController.m内でshowPageが呼び出された場合は正常に動作しています)

何か提案がありますか?

+0

Interface BuilderのIBActionコンセントにボタンを接続しましたか? – Dancreek

答えて

0

私がであることを考える:あなたのメインPhoneContentControllerしていますので

- (IBAction)toPageTwo:(id)sender; 
{ 
    NSLog(@"button clicked..."); 
    PhoneContentController * callSview = [[PhoneContentController alloc] init]; 
    [callSview showPage:2]; 

あなたは、新しいPhoneContentControllerを割り当てる必要がありません。 selfshowPageメッセージを送信してください。

- (IBAction)toPageTwo:(id)sender; 
{ 
    NSLog(@"button clicked..."); 
    [self showPage:2]; 

私はどのクラス、メソッドのbelog(しかし、私はそれがPhoneContentControllerで推測)に正確に知っていないので、これは単なる推測です。

関連する問題