2013-10-28 50 views
0

我是iOS編程新手。我試圖讓已知的HelloWorld應用程序,但應用程序不起作用。所述我該如何修復ViewController?

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 

線程1的

部分:信號SIGABRT錯誤。

2013-10-28 19:52:07.872 MerhabaDunya[2341:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/bb/Library/Application Support/iPhone Simulator/7.0.3/Applications/32CBEFAF-FFFB-4550-990A-6A33B02CF7D6/MerhabaDunya.app> (loaded)' with name 'ViewController'' 
*** First throw call stack: 
(
0 CoreFoundation      0x017395e4 __exceptionPreprocess + 180 
1 libobjc.A.dylib      0x014bc8b6 objc_exception_throw + 44 
2 CoreFoundation      0x017393bb +[NSException raise:format:] + 139 
3 UIKit        0x004cb39c -[UINib instantiateWithOwner:options:] + 951 
4 UIKit        0x0033d605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280 
5 UIKit        0x0033ddad -[UIViewController loadView] + 302 
6 UIKit        0x0033e0ae -[UIViewController loadViewIfRequired] + 78 
7 UIKit        0x0033e5b4 -[UIViewController view] + 35 
8 UIKit        0x002669fd -[UIWindow addRootViewControllerViewIfPossible] + 66 
9 UIKit        0x00266d97 -[UIWindow _setHidden:forced:] + 312 
10 UIKit        0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49 
11 UIKit        0x0027189a -[UIWindow makeKeyAndVisible] + 65 
12 MerhabaDunya      0x00002cdb -[AppDelegate application:didFinishLaunchingWithOptions:] + 683 
13 UIKit        0x00224355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309 
14 UIKit        0x00224b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536 
15 UIKit        0x002293a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824 
16 UIKit        0x0023d87c -[UIApplication handleEvent:withNewEvent:] + 3447 
17 UIKit        0x0023dde9 -[UIApplication sendEvent:] + 85 
18 UIKit        0x0022b025 _UIApplicationHandleEvent + 736 
19 GraphicsServices     0x036e02f6 _PurpleEventCallback + 776 
20 GraphicsServices     0x036dfe01 PurpleEventCallback + 46 
21 CoreFoundation      0x016b4d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 
22 CoreFoundation      0x016b4a9b __CFRunLoopDoSource1 + 523 
23 CoreFoundation      0x016df77c __CFRunLoopRun + 2156 
24 CoreFoundation      0x016deac3 CFRunLoopRunSpecific + 467 
25 CoreFoundation      0x016de8db CFRunLoopRunInMode + 123 
26 UIKit        0x00228add -[UIApplication _run] + 840 
27 UIKit        0x0022ad3b UIApplicationMain + 1225 
28 MerhabaDunya      0x00002f2d main + 141 
29 libdyld.dylib      0x01d7770d start + 1 
30 ???         0x00000001 0x0 + 1 
) 


libc++abi.dylib: terminating with uncaught exception of type NSException 

appdelegate.h

#import <UIKit/UIKit.h> 
@class ViewController; 
@interface AppDelegate : UIResponder <UIApplicationDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@property (strong, nonatomic) ViewController *viewController; 
@end 

appdeledage.m

#import "AppDelegate.h" 
#import "ViewController.h" 

@implementation AppDelegate 

@synthesize window=_window; 
@synthesize viewController=_viewController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.viewController=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
    self.window.rootViewController=self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@end 

ViewController.m #進口 「ViewController.h」

@implementation ViewController 

@synthesize etiket; 
@synthesize tus; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)basildi:(id)sender { 
    [etiket setText:@"Hello"]; 
} 
@end 

回答

2

從堆棧跟蹤中看來,您嘗試使用方法-initWithNibName:bundle:實例化UIViewController,但使用不存在或零的nib名稱。

確保您傳入的nib名稱參數確實存在,即存在名爲ExampleViewController.xib的文件,或者該參數不爲零。

編輯---

現在你已經張貼你的代碼,我可以進一步明確。文件ViewController.xib不存在,需要創建。或者,你可能有一個錯字。將該字符串與主包中的xib(如果有)進行比較。

編輯---

既然你提到的故事板,你應該在你的-...didFinishLaunching...方法返回YES。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    return YES; 
} 
+0

謝謝你的幫助 – Selim

0

如果您使用故事板,那麼您不應該調用initWithNibName。這聽起來像是在試圖將來自基於XIB的應用程序的代碼混合到基於故事板的應用程序中。這是行不通的。

從你的didFinishLaunchingWithOptions方法中取出所有代碼。只需返回YES。

+0

哦,我是新的。感謝您的幫助 – Selim

相關問題