Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when inheriting SAHistoryNavigationViewController #38

Closed
apouche opened this issue Jan 12, 2016 · 5 comments
Closed

Crash when inheriting SAHistoryNavigationViewController #38

apouche opened this issue Jan 12, 2016 · 5 comments

Comments

@apouche
Copy link
Contributor

apouche commented Jan 12, 2016

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
Copy link
Owner

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 added a commit to apouche/SAHistoryNavigationViewController that referenced this issue Jan 12, 2016
According to Apple documentation:
> 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.

Since this is exactly what's happening here, the OS triggers a trap and any controller subclassing SAHistoryNavigationViewController will crash as well.

Simply removing the delegate assignment solves this issue.
@apouche
Copy link
Contributor Author

apouche commented Jan 12, 2016

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

marty-suzuki added a commit that referenced this issue Jan 12, 2016
[#38] fixed crash when changing navbar delegate
@marty-suzuki
Copy link
Owner

Thank you :-)

@apouche
Copy link
Contributor Author

apouche commented Jan 12, 2016

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

@marty-suzuki
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants