質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1830閲覧

swiftエラーコードについて

sioa

総合スコア13

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2015/08/06 15:11

編集2015/08/07 01:34

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:. }

}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Stripe

2015/08/06 15:22

質問文を編集して、DetailViewControllerのコードを書いてください。
sioa

2015/08/06 15:30

detailの中身を記入致しました お手数ですが、どうぞよろしくお願いいたします
Stripe

2015/08/06 15:39

そのDetailViewControllerは、StoryBoard上でUISplitViewControllerを配置してからクラスを変更しているんですか?
sioa

2015/08/06 15:43

いいえ、story boardは一切使わず書こうとしています 何か間違っている箇所がありますでしょうか?
guest

回答1

0

ベストアンサー

UISplitViewControllerは、画面に表示させるよりも前に、viewControllersプロパティにViewController(つまりSplitViewの中身)を設定する必要があります。

投稿2015/08/06 15:51

Stripe

総合スコア2183

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sioa

2015/08/06 15:58

AppDelegateの方でNavigationControllerを追加したmasterViewContorollerとdetailViewControllerの二つをSplitViewContorollerにaddChildしているのでが、それではダメなのでしょうか?
Stripe

2015/08/06 16:14

質問文を編集して、AppDelegateのコードを書いてください。
sioa

2015/08/07 01:35

delegateのコードを追加致しました よろしくお願い致します
Stripe

2015/08/07 03:27

detailViewControllerは、UISplitViewControllerのサブクラスです。 detailViewControllerにも、子ViewControllerの設定が必要です。
sioa

2015/08/07 04:00

つまりditailの方に何か書き込むことになると思うのですが、どういったコードを書き込めばよろしいのでしょうか? 飲み込みが遅く申し訳ありません もう少々ご教授お願いいたします
sioa

2015/08/07 05:21

detailViewでUISplitViewControllerを消して、UIViewControllerに変更すると動きました! 長らくありがとうございます、本当に助かりました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問