SVWebViewController crashes on iPad with iOS 7 #75

Open
tp opened this Issue Nov 22, 2013 · 10 comments

Comments

Projects
None yet
8 participants

tp commented Nov 22, 2013

I get the following error when running the stock SVWebViewController from master on an iPad with iOS7 (or the simulator).

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UIToolbarButton imageForState:]: unrecognized selector sent to 
instance 0x8ab3260'

While Xcode breaks for the exception in viewWillDisappear on the previous controller, I found out that the following changes make the crash disappear:

In updateToolbarItems comment out these lines (in the iPad branch):

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)];
toolbar.items = items;
toolbar.barStyle = self.navigationController.navigationBar.barStyle;
toolbar.tintColor = self.navigationController.navigationBar.tintColor;

Since the UIToolbar is not used on the iPad I don't see any reason to have the code in there.

Sadly I am not proficient enough in iOS development to explain how this code could cause the previous crash.

Owner

samvermette commented Nov 24, 2013

Can't reproduce that crash... And the toolbar is used on iPad, it's where I display the 4 buttons.

tp commented Nov 25, 2013

I still get the buttons in the navigation bar on the iPad when I comment out the above lines.

I think the icons for iPad get set in this line self.navigationItem.rightBarButtonItems = items.reverseObjectEnumerator.allObjects;, where the previously created UIToolbar *toolbar is not used.

drewmca commented Jan 30, 2014

I had the same crash. You can reproduce by trying to show the nav bar in viewWillAppear method of a subclass. In many apps, the nav bar isn't always shown. Obviously it needs to be for this view controller. So normal practice is to show and hide it appropriately in the viewWillAppear/viewWillDisappear methods of the view controller that needs it. When you do that, you get the crash, with the message shown above.

tp commented Jan 30, 2014

We use the same navbar hiding technique in our app, so that might be reason.

Still works fine with the stuff commented out, though.

I also can reproduce. Funny thing is it only happens when I'm hiding the navigation bar on the view controller before it. Fixed by commenting out those four lines of code.

Had the same error. Thanks for the solution!

tp commented Jun 5, 2014

@danmorganshoeboxed Same here. The previous screen has its navigation bar hidden.

Same crash on iPad when the previous navigation bar is hidden, thanks @tp , I think it is because when viewDidLoad, the navigation bar is nil.

@tp Hey this is really helpful! You probably saved me alot of time trying to debug this issue!

Is there a solution for this in any of the branches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment