Flipping between views has UITableView position issue - objective-c

I have a UINavigationController within a UITabBarController. Within the navigation controller I have a ViewController that looks after flipping between two views using transitionWithView:duration:options:animations:completion one of the views i am trying to show is a TableView.
The problem is when showing the TableView it is off position.
and the flip view
I have tested flipping between two standard views without issue, it is only the TableView that shows off position. Also when the Tableview has more data then can be shown on screen the bottom rows are hidden by the Tabbar. It looks like the frame size is wrong but I am not sure how to proceed to fix the problem.
Full test project and code can be found on GitHub
Any suggestions or help is greatly appreciated.

The root of the problem is that you are using UIViewControllers (FlipSide and FlipMain) as subviews for FlipController which is itself a UIViewController. Prior to iOS 5 this was not supported and inevitably led to problems. iOS 5 adds support for a view controller hierarchy but requires that you use the appropriate new methods.
You have a couple of choices: restructure the view controllers so they are not nested, rewrite the sub-controllers as UIViews, or use addChildViewController to add the subcontrollers.
I've forked and modified your original code here to illustrate that changing to UIViews resolves the problem with layout.

It's a bit hard to answer without the full code, but I would try playing with the "wantsFullScreenLayout" property of your view controllers. I say that because the offset seems to be 20px high, which corresponds to the status bar's height...
Let me know if this helped ;-)

Related

Subview doesn't appear on Mavericks; works on Mountain Lion

I've found a problem in my OSX app that I think is a Mavericks bug.
I have the following hierarchy:
NSView
->NSScrollView
->NSClipView
->NSTableView
When the scroll view doesn't contain any records I'm creating an overlay view as a subview of the NSView, and positioning it above the other subviews. I do this using:
[containerView addSubview:overlay
positioned:NSWindowAbove
relativeTo:nil];
FYI, the overlay view is a custom NSView subclass with a drawRect to draw the overlay itself.
On Mountain Lion this works fine, but on Mavericks the overlay does not appear. Googling around I think this is because the overlay is not being positioned above the other sibling views.
I found these links for reference:
Display Order Messed Up
Maverick Issue When Adding Subview on NSView (Stack Overflow)
The second link suggests the following code to fix the issue, which it appears to do, but as I don't have any layer-backed views in my app this feels a bit off:
[overlay setWantsLayer:YES];
Can anyone suggest a workaround for this problem other than the one suggested?
EDIT: I've found that if I put an Xcode breakpoint in the original code (without the workaround) at the point after the subview is added the subviews get added correctly, and my overlay view is displayed. If I remove the breakpoint, the overlay view is no longer displayed. Does this behaviour indicate anything?
Thanks
Darren.
It looks like you've been bitten by overlapping views:
Note: For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view.
from Apple's Working With A View Heirarchy.
As you note, the common recommendation to fix this is to is to set a layer. However since 10.4 you can hide a view using setHidden:, see Hiding Views in the above reference. This may solve your particular problem as your overlap appears to be total (you don't want to see parts of both views, only one of them).
HTH

UISearchDisplayController Results Table Overlapping UISearchBar

I'm having a strange issue with my UISearchDisplayController. When the search display activates the frame of the background fading view and the tableview are incorrectly overlapping the UISearchBar. It appears the results tableview is not taking the offset for the UIStatusBar into account.
The ViewController is using auto layout. Since the application does not use any opaque bars, the view controller does not extend any of its edges.
Extend edges under top bars = NO,
under bottom bars = NO, and
under opaque bars = NO.
Here is the initial layout:
This is what happens when the search display activates:
And finally, here is the resulting output of the search:
I solved my own problem. A hard lesson learned. After a few hours of thinking "It really shouldn't be this hard." I realized that my instance of UISearchDisplayController was not properly linked to the API provided property of its parent view controller. If you're using UIStoryBoards / Interface Builder be sure to click on your ViewController and view its provided outlets in the inspector. If you see this:
Then something is wrong and you're going to run into issues just as I had. What you'll want to do is to click in that empty circle and drag to your instance of the Search Display Controller. If things are linked up right you should see this:
I foolishly didn't pay attention to this and created my own IBOutlet to reference the Search Display controller. That caused IB to null out the API provided outlet as a UIViewController can only support one Search Display Controller. If you need me to clarify anything let me know.

Xcode's auto layout is only effective in viewDidAppear and this is very problematic

After upgrading my project to iOS 6, I realized that auto layout is only effective in viewDidAppear and most of my code expects the view's frame to be available in viewDidLoad. This limitation renders the really nice auto layout feature almost useless for me. Is there any suggestions to help me use auto layout?
For example, sometimes the developer needs to adjust information about a subview based on where auto layout chooses to place that particular subview. The subview's final location cannot be ascertained by the developer until AFTER the user has already seen it. The user should not see these information adjustments but be presented the final results all at once.
More specifically: What if I want to change an image in a view based on where auto-layout places that view? I cannot query that location and then change the image without the user seeing that happen.
As a general rule, the views frame/bounds should never be relied on in viewDidLoad.
The viewDidLoad method only gets called once the view has been created either programmatically or via a .nib/.xib file. At this point, the view has not been setup, only loaded into memory.
You should always do your view layout in either viewWillAppear or viewDidAppear as these methods are called once the view has been prepared for presentation.
As a test, if you simply NSLog(#"frame: %#", NSStringFromCGRect(self.view.frame)); in both your viewDidLoad and viewWillAppear methods, you will see that only the latter method returns the actual view size in relation to any other elements wrapped around your view (such as UINavigationBar and UITabBar).
As told by #charshep in a comment, calling view.layoutIfNeeded() in viewWillAppear can do the trick.
Quote of his original comment
I had trouble getting a table view to appear at the correct scroll position when pushing it [...] because layout wasn't occurring until after viewWillAppear. That meant the scroll calculation was occurring before the correct size was set so the result was off. What worked for me was calling layoutIfNeeded followed by the code to set the scroll position in viewWillAppear.

UISplitviewController and UINavigationController

I have a splitviewController for my iPad app that uses a uinavigationcontroller in its detail view (right view controller). Everything is hooked up in interface builder and after calling:
[self.window addSubview: splitViewCpntroller.view]
I get the left and right views to display.
The problem is, the navigation bar's y position in my right view is wrong and offset a bit (I think 20px) downwards so that there is a gap between the status bar and the right view's navigation bar.
I've spent the whole afternoon trying to figure out what's wrong but I didn't find anything. Since its all hooked up in IB I can't show you much code.
I'm sure it's a simple thing I'm missing and since it's IB it's probably hard for you to follow what exactly I was doing - but maybe one of you encountered this before?
This is one of those questions that comes up pretty often, but for some reason it's hard to remember the answer. However, I think the root of your problem is that your view controller's view has a height that's too small -- try adding 20 pixels to the height, and also check its position.

Adding views to a rootController in a splitView

I am playing a little with the split view of iPad and I want to add different views to the rootView of the split. I can add one image, one view of one of my view controllers but, instead of that, I have problems with de rotations.
For example, sometimes appear a white bar on the top and I can't do anything to move it. Does someones know how to add views to the rootView perfectly? Is this correct or I have to make other things.
Thanks
David
Finally I resolve the problem: When I dismiss the popover I have to get out the animation. If I do this, all works fine.
But if someone can tell me the best practices to how to put views in root controller please :)