我對Objective-C頗爲陌生,而且我遇到了一個我似乎無法解決的問題! 當我啓動我的應用程序時,我有4個按鈕!這些按鈕中的每一個都應該重定向到另一個XIB文件(並且這些XIB文件中的每一個都會有一個按鈕返回)當我嘗試切換視圖時,應用程序崩潰
但是,當我嘗試按下按鈕1時,我的應用程序「崩潰」! 這是控制檯顯示我:
[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'
這裏就是我嘗試做: h文件
#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
PS:兩個viewControllers(Ge ttingStartedViewController & AppointmentViewController)被創建!
如果你們需要更多的代碼(只是發表評論)
THX
凱文
我的'main'xib是這個xib中的FirstView_iPhone.xib是4個按鈕,所以gettingStarted:被髮送(或者至少應該是)到GettingStartedViewController對象。我剛剛檢查了gettingstarted.xib,文件的所有者與GettingStartedViewController對象正確鏈接 – Kevin 2011-03-07 14:15:51
重要的是主視圖上按鈕的目標 - 操作連接,因此文件的gettingstarted.xib的所有者不相關。問題應該在FirstView_iPhone.xib中,它的文件所有者應該可能是UIApplication。我不知道如何將動作連接到UIApplication,如果它沒有聲明gettingStarted :,所以我不是100%確定的,但動作的目標必須是FirstViewController對象,而不是UIApplication對象。 – MHC 2011-03-07 14:24:48
我給FirstView_iPhone.xib的文件所有者FirstViewController的值,因爲否則我無法達到我的2個函數(gettingStarted:約會:)無論如何我把它改回到UIApplication並且通過IB中的First Responder我能夠達到我的2再次起作用。現在,當我啓動我的應用程序,並點擊他們不做任何事情!所以我寫了一些應該在控制檯中可見的文本,但是也沒有出現。 (感謝迄今爲止的幫助)) – Kevin 2011-03-07 14:38:52