2017-05-01 6 views
0

ViewView内のナビゲーション項目にBarButtonを追加しようとしていますが、これはPageViewControllerに分割されます。私はこのエラーを受け取った、私はこれはかなり簡単だろう考え出したが、私はボタンをタップすると:NavigationControllerからView ControllerへSegue NSExceptionの終了をスローする

libc++abi.dylib: terminating with uncaught exception of type NSException 

のXCodeのエディタが示しています。ここ

Thread 1: signal SIGABRT 

は私の設定です:

のViewControllerのw /ナビゲーションバーボタン:

class AudioBookViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate{ 

@IBAction func helpButtonPressed(_ sender: Any) { 
    performSegue(withIdentifier: Constants.Segues.SegueFromAudiobooksToHelp, sender: self) 

    //The exception is thrown when trying to perform the segue above 

    Thread.callStackSymbols.forEach{print(" ",$0)} 
} 
... 

カスタムクラスPageViewController:

class PageViewController: UIPageViewController,UIPageViewControllerDelegate, UIPageViewControllerDataSource { 

let screens = ["Screen1","Screen2"] 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.delegate = self as UIPageViewControllerDelegate 
    self.dataSource = self as UIPageViewControllerDataSource 
} 

override func viewDidAppear(_ animated: Bool) { 
    let vc = self.storyboard?.instantiateViewController(withIdentifier: screens[0]) 
    setViewControllers([vc!], // Has to be a single item array, unless you're doing double sided stuff I believe 
     direction: .forward, 
     animated: true, 
     completion: nil) 
} 

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { 
    if let identifier = viewController.restorationIdentifier, let index = screens.index(of: identifier){ 
     if index > 0{ 
      return self.storyboard?.instantiateViewController(withIdentifier: screens[index - 1]) 
     } 
    } 

    return nil 
} 

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { 
    if let identifier = viewController.restorationIdentifier, let index = screens.index(of: identifier){ 
     if index < screens.count - 1 { 
      return self.storyboard?.instantiateViewController(withIdentifier: screens[index + 1]) 
     } 
    } 

    return nil 
} 

func presentationCount(for pageViewController: UIPageViewController) -> Int { 
    return screens.count 
} 

func presentationIndex(for pageViewController: UIPageViewController) -> Int { 
    if let identifier = viewControllers?.first?.restorationIdentifier, let index = screens.index(of: identifier){ 
      return index 
    } 
    return 0 
} 

}

マイ定数列挙型:

struct Constants { 

struct NotificationKeys{ 
    ... 

} 

struct Segues { 
    .... 
    static let SegueFromAudiobooksToHelp = "SegueFromAudiobooksToHelp" 
    static let SegueFromTopicsToHelp = "SegueFromTopicsToHelp" 
    .... 
} 

struct RegistrationOutcome{ 
    ... 

} 
} 

そして、ここでセグエを表示私のストーリーボードのスクリーンショットです:

SegueはAudiobooksViewCからですこれは、スタックトレースを実行している私の最初の時間が...がうまくいけば、私はこれを正しくやっているヘルプボタン Segue from Audiobooks VC to Help VC

から送られたIBActionと、PageViewControllerにontroller。私はsegueコードの直後にprint stack文を実行しました。

0 KA Audio Book      0x00000001000102a8 _TFC13KA_Audio_Book23AudioBookViewController17helpButtonPressedfP_T_ + 260 
1 KA Audio Book      0x000000010001070c _TToFC13KA_Audio_Book23AudioBookViewController17helpButtonPressedfP_T_ + 72 
2 UIKit        0x000000019792bd30 <redacted> + 96 
3 UIKit        0x0000000197a9f880 <redacted> + 168 
4 UIKit        0x000000019792bd30 <redacted> + 96 
5 UIKit        0x000000019792bcb0 <redacted> + 80 
6 UIKit        0x0000000197916128 <redacted> + 452 
7 UIKit        0x0000000197916290 <redacted> + 812 
8 UIKit        0x000000019792b59c <redacted> + 584 
9 UIKit        0x000000019792b0c4 <redacted> + 2484 
10 UIKit        0x0000000197926328 <redacted> + 2988 
11 UIKit        0x00000001978f6da0 <redacted> + 340 
12 UIKit        0x00000001980e075c <redacted> + 2736 
13 UIKit        0x00000001980da130 <redacted> + 784 
14 CoreFoundation      0x00000001919eeb5c <redacted> + 24 
15 CoreFoundation      0x00000001919ee4a4 <redacted> + 524 
16 CoreFoundation      0x00000001919ec0a4 <redacted> + 804 
17 CoreFoundation      0x000000019191a2b8 CFRunLoopRunSpecific + 444 
18 GraphicsServices     0x00000001933ce198 GSEventRunModal + 180 
19 UIKit        0x00000001979617fc <redacted> + 684 
20 UIKit        0x000000019795c534 UIApplicationMain + 208 
21 KA Audio Book      0x000000010004f65c main + 76 
22 libdyld.dylib      0x00000001908fd5b8 <redacted> + 4 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

更新: 私は定期的にViewControllerをでPageViewControllerを交換してきましたし、セグエが正常に動作します。これは、問題が私がセグメンテーションしているPageViewControllerであることを確認します。私は、PageViewControllerの私の第一画面VCが作成されていないか、正しく参照されていると思います。これは私の初めてのPageViewControllerを使用しているので、私は何かが欠けている必要があります...

+0

何が提供されているかに基づいて診断するのは難しいです。コンソールに表示されたすべてを含めることはできますか?通常、そこにはもっと多くのものがあります(見た目ではわかりにくい/重要ではないかもしれませんが、しばしばそこから取り出せる情報があります)。これがなければ、スタックトレースも役に立ちます。また、例外ブレークポイントを追加すると、問題の原因となったコードの正確な行を特定することができます。 – Rob

答えて

0

私は解決策に達しました...私は完全にプログラムで私のページビューアコントローラを設定することができませんでした。代わりに、各ページのViewController Storyboard要素を作成し、PageViewController内の識別子に対応する各ViewController名を命名しなければなりませんでした。

「ストーリーボードIDを使用する」チェックボックスがオンになっていることを確認してください。

関連する問題