0

私はシンプルな 3 ページのアプリを持っています。左にスワイプして 1 ページから 2 ページに移動できます。

ただし、2 ページ目にいるときは、右にスワイプして 1 ページに移動するか、左にスワイプして 3 ページに移動する機能を追加する必要がありますが、クラッシュし続けます。

メモリ リリースの問題ではないかと思いますが、以下のコードに明らかなエラーがないか確認していただけないでしょうか。

どうもありがとう、

- (void)viewDidLoad {

    UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
    [swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
    [self.view addGestureRecognizer:swipeLeftRight];
    [UISwipeGestureRecognizer release];

}

- (IBAction)swipeLeftDetected:(UISwipeGestureRecognizer *)sender {


    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        Page3ViewController *UIViewController =
        [[Page3ViewController alloc] initWithNibName:@"Page3ViewController~ipad" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];
          [Page2ViewController release];
    }else{

        Page3ViewController *UIViewController =
        [[Page3ViewController alloc] initWithNibName:@"Page3ViewController" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];
        [Page2ViewController release];
    }

        }


- (IBAction)swipeRightDetected:(UISwipeGestureRecognizer *)sender {


    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        ViewController *UIViewController =
        [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];

        [Page2ViewController release];

    }else{

        ViewController *UIViewController =
        [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];

        ViewController *VC = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        [self presentModalViewController:VC animated:YES];

        [Page2ViewController release];

    }
}
4

2 に答える 2

0

編集:

handleGesture:ジェスチャレコグナイザーに渡すアクションであるため、呼び出されるメソッドを実装する必要があります。

于 2012-10-19T19:04:04.047 に答える
0

修正済み、rptwsthhi という人物による古い投稿を見つけたので、その一部を使用して修正しました。

viewDidLoad {

 UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
    rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [rightRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:rightRecognizer];
    [rightRecognizer release];

    //........towards left Gesture recogniser for swiping.....//
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [leftRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:leftRecognizer];
    [leftRecognizer release];

これを使用してページを切り替えます。

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //Do moving

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        ViewController *UIViewController =
        [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];

        [Page2ViewController release];

    }else{

        ViewController *UIViewController =
        [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];

        ViewController *VC = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        [self presentModalViewController:VC animated:YES];

        [Page2ViewController release];

    }
}

- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
    // do moving

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        Page3ViewController *UIViewController =
        [[Page3ViewController alloc] initWithNibName:@"Page3ViewController~ipad" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];


    }else{

        Page3ViewController *UIViewController =
        [[Page3ViewController alloc] initWithNibName:@"Page3ViewController" bundle:nil];
        [self presentModalViewController:UIViewController animated:YES];

    }

}

真のコーダーの視点でそれがどれほどうまく機能するかはわかりませんが、機能します。:)

于 2012-10-20T01:24:34.460 に答える