gpt4 book ai didi

ios - 我该如何修复 ViewController?

转载 作者:行者123 更新时间:2023-11-28 22:23:31 25 4
gpt4 key购买 nike

我是 iOS 编程新手。我试图制作已知的 HelloWorld 应用程序,但该应用程序不起作用。

一部分

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

Thread 1: Signal SIGABRT error.

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

应用委托(delegate).h

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

应用程序.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

最佳答案

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

确保您传入的 nib 名称参数确实存在,即名称为 ExampleViewController.xib 的文件存在,或者该参数不为 nil。

编辑---

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

编辑---

既然你提到了 Storyboard,你应该在你的 -...didFinishLaunching... 方法中返回 YES。

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

关于ios - 我该如何修复 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19641900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com