2012-09-14 3 views
1

현재 도달 할 수있는 사람의 수를 늘리기 위해 iOS4에서 내 앱을 사용할 수있게하려고합니다.iOS5에서 iOS4 충돌 - ViewController

우리는 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]; 

} 

어떻게 해결할 수 있습니까? 미리 감사드립니다!

+0

은 다음과 같습니다 코드에서 전화를하고, 반복해서 respondsToSelector 테스트 및 is deprecated 경고를 복제하지 않으며, 단지 UIViewController에 추가합니다 CatagoryViewController는 UIViewController 유형입니까? – Kyle

답변

6

presentViewController:animated:completion:은 iOS5 이상에서만 사용할 수 있습니다. 따라서 충돌이 발생할 수 있습니다.

변경에 마지막 부분하십시오의 ViewController를 제시의 새로운 방법이 지원되는 경우

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]; 

이 먼저 확인합니다. 앞으로는 잘 작동하는지 확인하기 위해 presentModalViewController:이 사용되지 않는 것으로 표시되었으므로 새로운 방법을 사용할 수없는 경우에만 해당 옵션을 사용합니다.

+0

고맙습니다. 둘의 차이점은 무엇입니까? –

+0

명백한 (완료 블록 핸들러) 외에, 둘 다 거의 동일합니다. 자세한 내용은 설명서를 확인하십시오. – Till

+0

알았어, 정말 고마워! –

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]; 
0

의 틸 솔루션은 지금까지 최고입니다.
하지만 나 같은, 당신이 현재/DismissModalViewController의 번호를 가지고있는 경우 :

@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 
관련 문제