アプリに新しい開始画面を追加しましたが、機能しなくなりました。ヘッダー、.m、.xib ファイルが追加されました。
まず、エラー:
キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: ' * -[__NSPlaceholderArray initWithObjects:count:]: オブジェクト [0] から nil オブジェクトを挿入しようとしています'
これはコントローラーです(何も変更していません):
#import "StartViewController.h"
@interface StartViewController ()
@end
@implementation StartViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
これは、AppDelegate の起動コードです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
} else {
//self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
// [self.window addSubview:navController.view];
return YES;
}
.xib は StartViewController.xib と呼ばれ、いくつかのラベルとボタンしかありません。まだ接続がありません。すべてを削除しようとしましたが、同じエラーが発生しました。
私はデバッガーを使用しましたが、新しいコントローラーのコンストラクターと viewdidload メソッドにも使用されます。[self.window makeKeyAndVisible];
デリゲートの行で例外がスローされます。
新しいコントローラーを古いコントローラーに接続する行を変更するだけでself.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
、アプリは再び機能します。
それは何ですか?それは非常に基本的なものでなければなりませんが、私はそれを見つけることができません。