swiftで開発をしていたのですが、ビルドは成功したものの起動直後に下記のようなエラーをふいてしまいました
2015-08-07 00:07:49.364 Solomon_ver_0.0.1[1689:1118725] Splitview controller <Solomon_ver_0_0_1.DetailViewController: 0x7fb06b727280> is expected to have a view controller at index 0 before it's used!
2015-08-07 00:07:49.372 Solomon_ver_0.0.1[1689:1118725] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] must not be called with nil
.'
*** First throw call stack:
libc++abi.dylib: terminating with uncaught exception of type NSException
このエラーコードはどういった意味なのでしょうか?
回答の方、何卒よろしくお願いいたします
detailのなかみは下記になります
import UIKit
class DetailViewController: UISplitViewController ,UISplitViewControllerDelegate {
override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.whiteColor() // ボタンの定義をおこなう. let myButton = UIButton(frame: CGRectMake(0,0,100,50)) myButton.backgroundColor = UIColor.orangeColor() myButton.layer.masksToBounds = true myButton.setTitle("ボタン", forState: .Normal) myButton.layer.cornerRadius = 20.0 myButton.layer.position = CGPoint(x: self.view.bounds.width/2, y:200) myButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside) // ボタンをViewに追加する. self.view.addSubview(myButton) // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func onClickMyButton(sender: UIButton){ println("ボタン押下") } func splitViewController(svc: UISplitViewController, willHideViewController aViewController: UIViewController, withBarButtonItem barButtonItem: UIBarButtonItem, forPopoverController pc: UIPopoverController) { //splitviewのボタンアイテムの設定 barButtonItem.title = "メニュー" self.navigationItem.leftBarButtonItem = barButtonItem } func splitViewController(svc: UISplitViewController, willShowViewController aViewController: UIViewController, invalidatingBarButtonItem barButtonItem: UIBarButtonItem) { self.navigationItem.leftBarButtonItem = nil }
}
以下appdelegate
lass AppDelegate: UIResponder, UIApplicationDelegate{
//UISplitiViewContorollerの初期設定 //それぞれのviewのインスタンスを作成 var window: UIWindow? var masterViewController = MasterViewController() var masterNavigationController = UINavigationController() var detailViewController = DetailViewController() var detailNavigationController = UINavigationController() var splitViewController = UISplitViewController() func splitVC() -> UISplitViewController{ //viewにnavigationの追加とタイトルの設定 //master masterViewController.title = "Master" masterNavigationController.addChildViewController(masterViewController) //detail detailViewController.title = "Detail" detailNavigationController.addChildViewController(detailViewController) //上記のnavigationをsplitViewを使い結合 splitViewController.addChildViewController(masterNavigationController) splitViewController.addChildViewController(detailNavigationController) //splitViewControllerのdelegateをmasterViewControllerに委託 splitViewController.delegate = detailViewController return splitViewController } func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. //windowのrootをsplitViewControllerに設定 self.window?.rootViewController = self.splitVC() self.window?.makeKeyAndVisible() return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. }
}
回答1件
あなたの回答
tips
プレビュー