1

I have a navigation controller in the master pane of a split view controller. It has a tint set on the navigation bar. When this navigation controller is displayed in the split view's popover, the popover does not show the navigation items in the black popover-style but instead the layout is kind of screwed up and it uses the tint that was set before:

The tint:

alt text http://img6.imageshack.us/img6/2650/tint.png

When displayed in the popover:

alt text http://img707.imageshack.us/img707/9725/screwedup.png

I tried handling willPresentViewController etc. to clear the tint before displaying in the popover, and restoring the tint when going back. This almost works but when transitioning back to landscape mode the standard iPad tint is visible during the animation before changing back, and the tint on some of the navigation items is not set back correctly:

Clearing the tint before showing the popover works:

alt text http://img38.imageshack.us/img38/3237/betterfq.png

But on the way back the buttons are left in an inconsistent state:

alt text http://img802.imageshack.us/img802/1937/inconsistent.png

Calling setNeedsDisplay etc. does not work.

Surely there's an easier way?

EDIT:

Apple has responded and this is a bug, filed as 8276014 on bugreport.apple.com. It should be fixed in 4.2 (from beta 2 onwards).

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • Come on, there must be a solution for this trivial problem? Even the apple developer forums have come up with nothing. – Mike Weller Aug 02 '10 at 10:22

3 Answers3

0

I think that you've found a very obscure bug in the SDK :) - You should file a bug report with Apple

I build a test app and got it to reproduce your problem :

  • Create a split pane project
  • Set the tint of the toolbar in the master pane (in DetailView) (to red)
  • Set the tint of the navigation item (to blue)
  • Add a few bar button items to check that the layout was OK
  • Ran the app

This showed the layout being wrong (as in your screenshots above)

Then I build another and it was absolutely fine :( The only difference between creating these apps was me not ever setting the tint of the navigation item in the popup view.

I tried setting the tint of the navigation item in my original project back to 'default' to see what happened and the layout bug was still there so whatever setting the tint does is irriversible as far as I can see.

I'd get in touch with Apple :)

Sam

PS I know this isn't really an answer but it's the best I have - I'm going to keep playing with it to see what's going on :)


OK, I've had a play around and can see what's happening - even though I'm not 100% sure I understand it.

I used git to take a snapshot of my working second project (the one with a tint on the master view toolbar but a working layout on the popup).

Then I broke it by setting the tint on the popup's navigation bar.

Then, I ran git diff and the only changes were (in my MainWindow.xib file)

    <bool key="IBUIClipsSubviews">YES</bool>
    <bool key="IBUIMultipleTouchEnabled">YES</bool>
    <string key="targetRuntimeIdentifier">IBIPadFramework</string>
+     <object class="NSColor" key="IBUITintColor">
+      <int key="NSColorSpace">1</int>
+      <bytes key="NSRGB">MSAwLjg4NTI1MDE4NjEgMC42NDExMjQ4OTI1AA</bytes>
+     </object>
    </object>

This is the new tint color added to the definition of my navigation controller and is what's breaking the layout.

I then went into interface builder an set the style of my popup's navigation bar to be 'Default' - the tint went back to default and when I ran the app it was fixed again.

Sure enough, when I did another git diff I found that the lines added above had been removed.

I then tried playing with the styles - I set the style to be 'Black Opaque' and ran the app - it stoll worked fine. This is because setting the style doesn't set a black tint, instead it adds this line to the xib :

+   <int key="IBUIBarStyle">1</int>

This tells me that you could either fix it by either

1) setting the style in interface builder

2) edit your xib file by hand to remove the lines that specify the tint

3) Setting the barStyle property in your code (but I'm not 100% sure this one would work)

Hope that's helpful, thank's for a challenge,

Sam

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • Sorry for the essay ;) I've had a play around and there should be an attempt at a real answer after the grey line :) – deanWombourne Aug 03 '10 at 10:50
  • you say DIFF shows extra lines in the xib if you add the tint. if thats causing the problem, maybe setting the tint through code would work.. – Swapnil Luktuke Aug 04 '10 at 05:43
  • I'd definitely try it but I think that it's the fact that the tint is set, not the way you're setting it that's the problem - though that's just a hunch :) - perhaps the bug isn't in the layout code but is in the initWithCoder method of the navigation bar. Nice idea though - definitely worth a try :) – deanWombourne Aug 04 '10 at 08:29
  • Sorry but this is of no help at all. First of all I'm not using nibs, second the reason setting the tint to default in IB works is because the default is a tint of nil which always works properly. I need to use a custom tint obviously. Setting the bar style does not work either. – Mike Weller Aug 05 '10 at 06:24
  • In fact this has nothing to do with nibs or the code in them. It's simply that a UIColor tint on the navigation bar screws up the popover. Whether that is done through a nib or not is irrelevant. – Mike Weller Aug 05 '10 at 06:31
  • Ah, I just assumed that you were using nibs. Try my other answer! – deanWombourne Aug 05 '10 at 11:37
0

my last answer was completely on the wrong track!

This code removes the tint after a rotation to a portrait mode and sets the tint before a rotation to a landscape mode :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:orientation duration:duration];

    if (orientation == UIInterfaceOrientationLandscapeLeft ||
        orientation == UIInterfaceOrientationLandscapeRight) {
        [bar setTintColor:[UIColor redColor]];  
    }
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIInterfaceOrientationPortrait ||
        orientation == UIInterfaceOrientationPortraitUpsideDown) {
        [bar setTintColor:nil];
    } 
}

This is in the main view controller (the one that contains the split pane view) and shows a red bar in landscape and a correctly formatted black one in portrait modes.

You say that you've tried it in the willPresentViewController and it didnt work - this seems to work for me putting it in these two methods.

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
0

As it turns out, this was a bug that was confirmed by apple (8276014 on bugreport.apple.com) and fixed in iOS 4.2. I was never able to find any acceptable workarounds.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151