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 at -[UINavigationBar viewCount] #4

Closed
ultragtx opened this issue Jan 19, 2013 · 11 comments
Closed

Crash at -[UINavigationBar viewCount] #4

ultragtx opened this issue Jan 19, 2013 · 11 comments

Comments

@ultragtx
Copy link

A simple but may not correct fix

in file CustomNavigationController.m >> initWithRootViewController:

  • replace with all the code in -(id)init
  • add [self pushViewController:rootViewController animated:NO]; at the end of if(self) {

hope this helps

@Kjuly
Copy link
Owner

Kjuly commented Jan 19, 2013

Thanks you, but what's the version of your SDK? iOS 5.0 at least. :)

@Kjuly
Copy link
Owner

Kjuly commented Jan 19, 2013

And hi @ultragtx , can you paste your crash log here, please?

@ultragtx
Copy link
Author

you should remove your session by delete and reinstall the app and you will see how it crash at launch

@ultragtx
Copy link
Author

oh,seems that simply delete the app cannot clear the session

@Kjuly
Copy link
Owner

Kjuly commented Jan 20, 2013

What's session? Do you mean the app content?

@ultragtx
Copy link
Author

Google OAuth
在 2013-1-20,下午7:35,Kaijie Yu notifications@github.com 写道:

What's session? Do you mean the app content?


Reply to this email directly or view it on GitHub.

@Kjuly
Copy link
Owner

Kjuly commented Jan 20, 2013

Sorry @ultragtx, I tried several times but without any crash issue at -[UINavigationBar viewCount]... :?

Your crash might occurs in the message below ( CustomNavigationController.m ):

- (void)pushViewController:(UIViewController *)viewController
                        animated:(BOOL)animated {
  ...
  // If |viewCount| == 2, add |backButton| for previous view
  if (++((CustomNavigationBar *)self.navigationBar).viewCount == 2)
    [(CustomNavigationBar *)self.navigationBar addBackButtonForPreviousView];
  ...
}

Here the navigationBar is a CustomNavigationBar, so it'll crash if you push vc (by sending -pushViewController:animated: message) before the custom navigationBar is initialized correctly, cause the default navigationBar does not have the viewCount property.

And if you put a log in -initWithRootViewController: of CustomNavigationController.m, you'll find that: When you send -initWithRootViewController:, it'll send -init first.

So just use -initWithRootViewController: to initialize your navigation controller is fine.


B.t.w, you can refresh your session in this way: Logout in "Settings View" & re-login via VPN or SSH (in CN).

@ultragtx
Copy link
Author

Log:
2013-01-20 23:21:21:743 iPokeMon[2271:2311] -[AppDelegate application:didFinishLaunchingWithOptions:] [Line 45] Register Defaults From Settings.bundle...
2013-01-20 23:21:21:795 iPokeMon[2271:2311] -[AppDelegate persistentStoreCoordinator] [Line 232] >>> storePath: /var/mobile/Applications/15F613D1-E7B1-4851-8B48-A48634E53C46/Documents/Pokemon.sqlite3 ---
2013-01-20 23:21:22:013 iPokeMon[2271:2311] TestFlight: Started Session
2013-01-20 23:21:22:351 iPokeMon[2271:2311] TestFlight: Crash Handlers are installed
2013-01-20 23:21:22:466 iPokeMon[2271:2311] -[OAuthManager isSessionValid] [Line 102] CHECKING SESSION...
2013-01-20 23:21:22:475 iPokeMon[2271:2311] -[OAuthManager isSessionValid] [Line 105] INVALID SESSION...
2013-01-20 23:21:22.603 iPokeMon[2271:907] -[UINavigationBar viewCount]: unrecognized selector sent to instance 0x1e513800

Strange behavior, Code run this way

CustomNavigationController.m

I set several break point, stopped at #1 >> #3 >> #4(crash) but did not stop at #2, wonder why pushViewController:animated can be called by [super initWithRootViewController:]

Also, the crash can be repeated both on a device and the simulator, but when I fix the crash using the method I post, the crash cannot be repeated even I fully reset the simulator. Still crash on the device, because I did not run the modified code on it.

在 2013-1-20,下午10:57,Kaijie Yu notifications@github.com 写道:

Sorry @ultragtx, I tried several times but without any crash issue at -[UINavigationBar viewCount]... :?

Your crash might occurs in the message below ( CustomNavigationController.m ):

  • (void)pushViewController:(UIViewController *)viewController
    animated:(BOOL)animated {
    ...
    // If |viewCount| == 2, add |backButton| for previous view
    if (++((CustomNavigationBar *)self.navigationBar).viewCount == 2)
    [(CustomNavigationBar *)self.navigationBar addBackButtonForPreviousView];
    ...
    }
    Here the navigationBar is a CustomNavigationBar, so it'll crash if you push vc (by sending -pushViewController:animated: message) before the custom navigationBar is initialized correctly, cause the default navigationBar does not have the viewCount property.

And if you put a log in -initWithRootViewController: of CustomNavigationController.m, you'll find that: When you send -initWithRootViewController:, it'll send -init first.

So just use -initWithRootViewController: to initialize your navigation controller is fine.

B.t.w, you can refresh your session in this way: Logout in "Settings View" & re-login via VPN or SSH (in CN).


Reply to this email directly or view it on GitHub.

@Kjuly
Copy link
Owner

Kjuly commented Jan 20, 2013

Yes, it's so weird...

BreakPoint #2 will be focused last, and -init will be dispatched in BreakPoint #1.

About -initWithRootViewController:, it said:

This is a convenience method for initializing the receiver and pushing a root view controller onto the navigation stack. Every navigation stack must have at least one view controller to act as the root.

So it'll do the initialization job (send -init) before pushing root vc (send -pushViewController:animated:).


My Log looks like this:

2013-01-20 23:52:02:813 iPokeMon[9596:90371] TestFlight: Started Session
2013-01-20 23:52:02:853 iPokeMon[9596:90371] TestFlight: Crash Handlers are installed
2013-01-20 23:52:02:879 iPokeMon[9596:90371] -[OAuthManager isSessionValid] [Line 102] CHECKING SESSION...
2013-01-20 23:52:02:886 iPokeMon[9596:90371] -[OAuthManager isSessionValid] [Line 105] INVALID SESSION...
2013-01-20 23:52:02:911 iPokeMon[9596:90371] -[CustomNavigationController init] [Line 23] ......INIT......
2013-01-20 23:52:02:935 iPokeMon[9596:90371] -[CustomNavigationBar setBackToRootButtonToHidden:animated:] > > [Line 135] --- |CustomNavigationBar|: hide navigation bar...


Does your -init like this right now?

- (id)init {
  self = [super initWithNibName:nil bundle:nil];
  if (self) {
    NSLog(@"......INIT......");
    CustomNavigationBar * customNavigationBar = [CustomNavigationBar alloc];
    [customNavigationBar initWithFrame:CGRectMake(0.f, 0.f, kViewWidth, kNavigationBarHeight)];
    customNavigationBar.delegate = self;
    [self setValue:customNavigationBar forKey:@"navigationBar"];
    [customNavigationBar release];
    [self setNavigationBarHidden:YES];
  }
  return self;
}

@Kjuly
Copy link
Owner

Kjuly commented Jan 21, 2013

I found the key issue:

In iOS6.0 -initWithRootViewController: will not send -init message.

So as a fix, you can just do the navigation bar setting job before -initWithRootViewController:.

- (id)initWithRootViewController:(UIViewController *)rootViewController {
  [self _setupNavigationBar];
  self = [super initWithRootViewController:rootViewController];
  if (self) {
  }
  return self;
}

...

- (void)_setupNavigationBar {
  CustomNavigationBar * customNavigationBar = [CustomNavigationBar alloc];
  [customNavigationBar initWithFrame:CGRectMake(0.f, 0.f, kViewWidth, kNavigationBarHeight)];
  customNavigationBar.delegate = self;
  [self setValue:customNavigationBar forKey:@"navigationBar"];
  [customNavigationBar release];
  [self setNavigationBarHidden:YES];
}

@Kjuly
Copy link
Owner

Kjuly commented Jan 21, 2013

You can pull my commits on dev branch right now. :)

@Kjuly Kjuly closed this as completed Jan 22, 2013
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