1

現在、私は自分のアプリを iOS4 で利用できるようにして、リーチできる人の数を増やしようとしています。

StoryBoard から離れ、代わりに .xib ファイルを使用するようになりました。

現在、これを止めているのは次のエラーだけです。

2012-09-14 18:32:42.705 CrunchCalculator[7037:11303] -[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230
2012-09-14 18:32:42.707 CrunchCalculator[7037:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x013625a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00ef1313 objc_exception_throw + 44
    2   CoreFoundation                      0x013640bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x012d3966 ___forwarding___ + 966
    4   CoreFoundation                      0x012d3522 _CF_forwarding_prep_0 + 50
    5   CrunchCalculator                    0x0002e560 +[OpenCalcViewController openCalcView:fromViewController:] + 8256
    6   CrunchCalculator                    0x0002fe0a -[CategoryViewController openCalc:] + 106
    7   UIKit                               0x002554fd -[UIApplication sendAction:to:from:forEvent:] + 119
    8   UIKit                               0x002e5799 -[UIControl sendAction:to:forEvent:] + 67
    9   UIKit                               0x002e7c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    10  UIKit                               0x002e67d8 -[UIControl touchesEnded:withEvent:] + 458
    11  UIKit                               0x004e84de _UIGestureRecognizerSortAndSendDelayedTouches + 3609
    12  UIKit                               0x004e8c53 _UIGestureRecognizerUpdateObserver + 927
    13  CoreFoundation                      0x0134389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
    14  CoreFoundation                      0x012d86e7 __CFRunLoopDoObservers + 295
    15  CoreFoundation                      0x012a11d7 __CFRunLoopRun + 1575
    16  CoreFoundation                      0x012a0840 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x012a0761 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x014b61c4 GSEventRunModal + 217
    19  GraphicsServices                    0x014b6289 GSEventRun + 115
    20  UIKit                               0x00263c93 UIApplicationMain + 1160
    21  CrunchCalculator                    0x0000276a main + 170
    22  CrunchCalculator                    0x000026b5 start + 53
)
terminate called throwing an exception(lldb) 

通常、これを使用して別のビューを開きます。

    UIViewController *controller;
    controller = [[CategoryViewController alloc]initWithNibName:@"CategoryViewController" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:controller animated:YES];
    [controller release];

ただし、この場合、次のコードを使用して (効率のために) 別のファイルから関数を呼び出します。

#import "AllofTheFiles.h"

+ (void)openCalcView: (NSString *)nameOfView fromViewController:(UIViewController *)controller {

    NSUserDefaults *saveSpot = [NSUserDefaults standardUserDefaults];

    UIViewController *modalController;

    if ([nameOfView isEqualToString:@"Tax"]) {

        modalController= [[TAXViewController alloc]initWithNibName:@"TAXViewController" bundle:nil];

    }else if ([nameOfView isEqualToString:@"Rent"]){

        modalController= [[RENTViewController alloc]initWithNibName:@"RENTViewController" bundle:nil];

    }  //... cut other else if's to save space

modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller presentViewController:modalController animated:YES completion:nil];
[modalController release]; 

}

どうすればこれを修正できますか? 前もって感謝します!

4

3 に答える 3

6

presentViewController:animated:completion:は iOS5 以降でのみ使用できるため、そのクラッシュが発生します。

最後の部分を次のように変更します。

modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//do we support the new way of presenting a modal viewController?
if ([controller respondsToSelector:@selector(presentViewController:animated:completion:)])
{   //yes->so do it!
    [controller presentViewController:modalController animated:YES completion:NULL];
}
else
{   //nope->we seem to be running on something prior to iOS5, do it the old way!
    [controller presentModalViewController:modalController animated:YES];
}
[modalController release]; 

これはまず、viewController を表示する新しい方法がサポートされているかどうかを確認します。非推奨としてマークされているように、これが将来的に正常に機能することを確認するためにpresentModalViewController:、新しい方法が利用できない場合にのみそのオプションを使用します。

于 2012-09-14T22:45:00.800 に答える
0

navcontroller を提示するか、presentModalViewController を使用する必要がある場合があります。次のことを試してください。

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalController];
navController.modalPresentationStyle = UIModalPresentationPageSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller  presentModalViewController:navController animated:YES completion:nil];
[modalController release];
[navController release];
于 2012-09-14T22:52:42.000 に答える
0

Till のソリューションは、はるかに優れています。
しかし、私のように、コード内に多数の present/DismissModalViewController: 呼び出しがあり、respondsToSelectorテストとis deprecated警告を何度も繰り返したくない場合は、UIViewController を追加してください。

@implementation UIViewController (iOS4Compatibility)

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag {
    if([self respondsToSelector:@selector(presentViewController:animated:completion:)])
        [self presentViewController:viewControllerToPresent animated:flag completion:nil];
    else
        [self presentModalViewController:viewControllerToPresent animated:flag];
}

- (void)dismissViewControllerAnimated:(BOOL)flag {
    if([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
        [self dismissViewControllerAnimated:flag completion:nil];
    else
        [self dismissModalViewControllerAnimated:flag];
}

@end
于 2012-09-20T15:15:21.307 に答える