2011-03-07 3 views
0

저는 Objective-C에 익숙하지 않고 수정할 수없는 문제가 있습니다! 응용 프로그램을 시작할 때 버튼이 4 개 있습니다! 이러한 각 단추는 다른 XIB 파일로 리디렉션해야합니다 (및 각 XIB 파일에는 다시 돌아갈 단추가 있습니다)보기를 전환하려고하면 응용 프로그램이 중단됩니다.

그러나 단추 중 하나를 누르면 응용 프로그램이 "충돌"합니다! 내가 할 시도하고있는 무슨

[Session started at 2011-03-07 14:15:38 +0100.] 
2011-03-07 14:15:42.169 Google Calendar[1332:207] -[UIApplication gettingStarted:]: unrecognized selector sent to instance 0x4c17fa0 
2011-03-07 14:15:42.173 Google Calendar[1332:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UIApplication gettingStarted:]: unrecognized selector sent to instance 0x4c17fa0' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x0124bbe9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x013a05c2 objc_exception_throw + 47 
    2 CoreFoundation      0x0124d6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x011bd366 ___forwarding___ + 966 
    4 CoreFoundation      0x011bcf22 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x00502a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    6 UIKit        0x005911b5 -[UIControl sendAction:to:forEvent:] + 67 
    7 UIKit        0x00593647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    8 UIKit        0x005921f4 -[UIControl touchesEnded:withEvent:] + 458 
    9 UIKit        0x005270d1 -[UIWindow _sendTouchesForEvent:] + 567 
    10 UIKit        0x0050837a -[UIApplication sendEvent:] + 447 
    11 UIKit        0x0050d732 _UIApplicationHandleEvent + 7576 
    12 GraphicsServices     0x01968a36 PurpleEventCallback + 1550 
    13 CoreFoundation      0x0122d064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    14 CoreFoundation      0x0118d6f7 __CFRunLoopDoSource1 + 215 
    15 CoreFoundation      0x0118a983 __CFRunLoopRun + 979 
    16 CoreFoundation      0x0118a240 CFRunLoopRunSpecific + 208 
    17 CoreFoundation      0x0118a161 CFRunLoopRunInMode + 97 
    18 GraphicsServices     0x01967268 GSEventRunModal + 217 
    19 GraphicsServices     0x0196732d GSEventRun + 115 
    20 UIKit        0x0051142e UIApplicationMain + 1160 
    21 Google Calendar      0x00002304 main + 102 
    22 Google Calendar      0x00002295 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

을 그리고 여기에 있습니다 : : 이 콘솔이 저를 보여줍니다 무엇 시간 파일

에게
#import <UIKit/UIKit.h> 

@interface FirstViewController : UIViewController { 

} 
-(IBAction)gettingStarted:(id)sender; 
-(IBAction)appointments:(id)sender; 

@end 

m-파일을

#import "FirstViewController.h" 
#import "AppointmentViewController.h" 
#import "GettingStartedViewController.h" 

@implementation FirstViewController 

-(IBAction)gettingStarted:(id)sender { 
    GettingStartedViewController *gettingStartedVC = [[GettingStartedViewController alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:gettingStartedVC animated:YES]; 
} 
-(IBAction)appointments:(id)sender { 
    AppointmentViewController *appointmentVC = [[AppointmentViewController alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:appointmentVC animated:YES]; 
} 
-(void)dealloc { 
    [super dealloc]; 
} 

@end 

추신 : 두 viewController (Ge ttingStartedViewController & AppointmentViewController)가 생성되었습니다!

너희들이 더 많은 코드가 필요하면

들으 (단지 코멘트를 남기시)

케빈

답변

0

gettingStarted: 메시지가 UIApplication 객체가 아닌 FirstViewController 개체로 전송됩니다 보인다. IB에서 연결을 할 때 모든 것이 올바른지 (File 's Owner 등) 확인하십시오.


Nib를 사용하는 일반적인 패턴은 Nib를 사용하여 FirstViewController를 만드는 것입니다. FirstView_iPhone.xib에는 viewcontroller 객체가 있으며 그 중 클래스 이름은 FirstViewController로 설정됩니다. 그런 다음 Nib가로드되면 FirstViewController 객체가 생성됩니다. 또한 해당 메소드를 IB의 조치로 사용할 수 있습니다.

기술적으로 FirstView_iPhone.xib에 외부 개체를 추가하고 해당 클래스를 FirstViewController로 설정하여 대상 작업 연결을 만들 수 있습니다.

프로그래밍 방식으로보기 컨트롤러 개체를 만들려면 setTarget:action: 메서드를 사용하여 프로그래밍 방식으로 대상 - 동작 연결을 추가 할 수 있습니다.

+0

내 '기본'xib는이 xib의 FirstView_iPhone.xib이므로 4 개의 버튼이므로 gettingStarted :는 GettingStartedViewController 객체로 전송됩니다. 방금 getstarted.xib를 확인했고 파일 소유자가 GettingStartedViewController 객체와 올바르게 연결되었습니다. – Kevin

+0

중요한 점은 주보기의 단추에서 대상 - 작업 연결이므로 파일의 gettingstarted.xib 소유자와 관련이 없습니다. 문제는 FirstView_iPhone.xib에 있어야하며 파일 소유자는 UIApplication이어야합니다.getStarted :를 선언하지 않으면 액션을 UIApplication에 연결하는 것이 가능한지 궁금합니다. 그렇기 때문에 100 % 확신 할 수는 없지만 액션 타겟은 UIApplication 객체가 아닌 FirstViewController 객체 여야합니다. – MHC

+0

다른 사람의 기능 (gettingStarted : and appointments :)에 연결할 수 없기 때문에 FirstView_iPhone.xib의 File 's Owner에 FirstViewController 값을주었습니다. 어쨌든 UIApplication으로 다시 변경했고 IB의 첫 번째 응답자를 통해 내 2에 도달했습니다. 다시 기능합니다. 이제 내 앱을 실행하고 뭔가를 클릭하면 아무 것도하지 않습니다. 그래서 콘솔에 표시되어야하는 작은 텍스트를 작성했지만 그 텍스트는 나타나지 않습니다. (지금까지 도움을 주셔서 감사합니다.) – Kevin

0

분명히 gettingStarted: 메시지가 잘못된 개체로 전송되었습니다. 출력 된 콘솔 출력은 메시지가 UIApplication으로 보내지고 있음을 나타냅니다. IB에서 귀하의 행동을 올바르게 파악하십시오. 작업을 시작하려는 버튼에서 IB 문서의 FirstViewController 객체로 Ctrl 키를 누른 상태에서 드래그하고 gettingStarted:을 선택합니다. 그런 다음 NSLog 문을 메소드 구현에 추가하여 호출되는지 확인하십시오.

관련 문제