我是iOS编程新手。我试图创建已知的HelloWorld应用程序但该应用程序不起作用。
的一部分
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 #import“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
答案 0 :(得分:2)
从堆栈跟踪中,您似乎尝试使用方法UIViewController
实例化-initWithNibName:bundle:
,但使用不存在或nil的nib名称。
确保您传入的nib名称参数确实存在,即存在名称为ExampleViewController.xib
的文件,或参数不为nil。
编辑---
现在您已经发布了代码,我可以进一步澄清。文件ViewController.xib
不存在,需要创建。或者,您可能有拼写错误。将字符串与主要包中的xib
(如果有)进行比较。
编辑---
现在您提到了故事板,您应该在-...didFinishLaunching...
方法中返回YES。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
答案 1 :(得分:0)
如果您正在使用故事板,那么您不应该调用initWithNibName。听起来你正试图将基于XIB的应用程序的代码混合到基于故事板的应用程序中。那不行。
从didFinishLaunchingWithOptions方法中删除所有代码。只需返回YES。