0

我是 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

应用代理.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 
4

2 回答 2

2

从堆栈跟踪来看,您似乎正在尝试UIViewController使用该方法实例化 a ,-initWithNibName:bundle:但使用一个不存在的或 nil nib 名称。

确保您传入的 nib name 参数确实存在,即存在具有 name 的文件ExampleViewController.xib,或者该参数不是 nil。

编辑 - -

现在您已经发布了代码,我可以进一步澄清。该文件ViewController.xib不存在,需要创建。或者,您可能有错字。将字符串与xib主包中的 (如果有)进行比较。

编辑 - -

既然您提到了故事板,您应该在-...didFinishLaunching...方法中返回 YES。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}
于 2013-10-28T18:08:18.737 回答
0

如果您使用情节提要,那么您不应该调用 initWithNibName。听起来您正在尝试将基于 XIB 的应用程序中的代码混合到基于故事板的应用程序中。那是行不通的。

从您的 didFinishLaunchingWithOptions 方法中删除所有代码。只需返回 YES。

于 2013-10-28T18:21:11.737 回答