2

別のviewControllerに切り替えたい。ビューにUIButtonがあり、次のコードを使用してUIButtonにUILongPressGestureRecognizerがあります。

UILongPressGestureRecognizer *buttonLongPressRecognizer;
buttonLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LoadButtonSettings:)];

buttonLongPressRecognizer.numberOfTouchesRequired = 1;
buttonLongPressRecognizer.minimumPressDuration = 2.0;

[NewButton addGestureRecognizer:buttonLongPressRecognizer];

viewControllersを切り替えるために使用するアクションは次のとおりです。

- (IBAction)LoadButtonSettings:(id)sender {

[ButtonSettingsViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[self presentViewController:ButtonSettingsViewController animated:YES completion:NULL];

}

問題は、ボタンを長押しするとアプリがクラッシュし、SIGABRTエラーが発生することです。奇妙なことに、それは私のiPhoneでのみ発生し、シミュレータでは発生しません。

私も使ってみました

    [self presentModalViewController:ButtonSettingsViewController animated:YES];

同じ問題が発生しました。私が知っているように、SIGABRTはメモリの問題があることを意味しますが、自動参照カウンターがオンになっているためわかりません。

これを修正する方法について何かアイデアはありますか?

前もって感謝します :)

4

2 に答える 2

3

ButtonSettingsViewControllerがViewControllerのタイプである場合、最初に初期化する必要があります。

- (IBAction)LoadButtonSettings:(id)sender {
    // init & alloc - Replace with your custom view controllers initialization method (if applicabale)
    ButtonSettingsViewController *viewController = [[ButtonSettingsViewController alloc] initWithNibNamed:@"ButtonSettingsViewController" bundle:nil];

    [viewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:viewController animated:YES completion:NULL];
}
于 2011-09-18T22:21:21.893 に答える
2

presentModalViewController:animated:ビューコントローラーオブジェクトが必要です。クラス(ButtonSettingsViewController)を渡します。まず、ViewControllerオブジェクトをインスタンス化します。

ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];

次に、そのビューコントローラオブジェクトのmodalTransitionStyleプロパティを設定します。

viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

次にそれを提示します:

[self presentModalViewController:viewControllerObject animated:YES];
于 2011-09-18T22:22:54.533 に答える