marty-suzuki / SAHistoryNavigationViewController

SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!
MIT License
1.57k stars 91 forks source link

Crash when inheriting SAHistoryNavigationViewController #38

Closed apouche closed 8 years ago

apouche commented 8 years ago

I gave this lib a try but discovered a nasty crash when using it on iOS 9.2 Here's the end of the stack trace.

* thread #1: tid = 0x9b91cc, 0x0000000103fd1dbb libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000103fd1dbb libobjc.A.dylib`objc_exception_throw
    frame #1: 0x000000010304ad9d CoreFoundation`+[NSException raise:format:] + 205
    frame #2: 0x0000000101466f0a UIKit`-[UINavigationBar setDelegate:] + 81
  * frame #3: 0x00000001012c228a SAHistoryNavigationViewController`SAHistoryNavigationViewController.SAHistoryNavigationViewController.viewDidLoad (self=<unavailable>)() -> () + 1418 at SAHistoryNavigationViewController.swift:101
    frame #4: 0x0000000100337059 CaptainJet`CaptainJet.CaptainJetNavigationController.viewDidLoad (self=0x00007fc03304e200)() -> () + 41 at CaptainJetNavigationController.swift:16
    frame #5: 0x0000000100337932 CaptainJet`@objc CaptainJet.CaptainJetNavigationController.viewDidLoad (CaptainJet.CaptainJetNavigationController)() -> () + 34 at CaptainJetNavigationController.swift:0
    frame #6: 0x0000000101508f98 UIKit`-[UIViewController loadViewIfRequired] + 1198
    frame #7: 0x00000001015092e7 UIKit`-[UIViewController view] + 27
    frame #8: 0x000000010155184b UIKit`-[UINavigationController pushViewController:transition:forceImmediate:] + 663
    frame #9: 0x0000000101551299 UIKit`-[UINavigationController pushViewController:animated:] + 848
    frame #10: 0x00000001012c28d8 

The debugger gives this output: Cannot manually set the delegate on a UINavigationBar managed by a controller.

Looking at the documentation you can see that:

If the navigation bar was created by a navigation controller and is being managed by that object, you must not change the value of this property. Navigation controllers act as the delegate for any navigation bars they create.

This is what is happening here. The controller automatically becomes the navigationBar delegate. I think this line should be removed. Let me know if you need a PR I would happily do so.

marty-suzuki commented 8 years ago

Thanks for your report.

At the early stage, I implemented custom navigation delegate, but that had changed this PR. It seems like he want to handle popViewController with UINavigationBarDelegate. (this line) Then I agreed this because I thought that is more smart than custom navigation delegate I wrote.

But those changes seems to cause a crashing. therefore i'll fix them.

apouche commented 8 years ago

I've opened PR #39 to fix this feel free to look at it, it's a very simple fix

marty-suzuki commented 8 years ago

Thank you :-)

apouche commented 8 years ago

awesome, can you let me know when you make a new release so that i can update my Podfile ? Thanks

marty-suzuki commented 8 years ago

I've released v2.3.0! Please try it!