iPad: UISplitViewController top gets cut off inside UITabViewController - objective-c

I have a UITabViewController which contains a UISplitViewController as the first view. When the app loads and shows the split controller, the top of the two views are cut off and shifted down a maybe 15 pixels. Clicking another tab fixes the problems and jumps both views back up:
When app loads:
After clicking another tab problem is corrected:
Code being used (unimportant stuff left out):
NewsSplit *newsTemp = [[NewsSplit alloc] init];
...
// The view controllers to the tabBar
[tabController setViewControllers:[NSArray arrayWithObjects:newsSplit, eventSplit, classesSplit, dirSplit, settings, nil]];
...
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
Why would the top be cut off and shifted down?

The short of it is that UISplitViewController isn't supposed to be embedded within another view controller. It's meant to be the root view controller of your window. I've run into this exact same issue in the past. Support for things such as rotation was glitchy. I eventually got it working like I wanted, but it was a hassle.
Unless they've improved things, I think you're going to have to subclass some things and shift frames around to get it to look right.

Related

Need clarity on if I'm switching View Controllers correctly

I'm making an ipad app which has 11 view controllers in storyboard, one of which is a master view that contains buttons to control which of the other view controllers is displayed as its subview.
Does anybody know for sure if it's ok to use UIViewControllers as subviews of other UIViewControllers, with hard evidence from apple or another source? It has been working flawlessly for me using this method so far:
int nextPage = (method to determine nextPage based on button pressed);
[currentView.view removeFromSuperview];
currentView = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:#"page%i",nextPage]];
[self.view insertSubview:currentView.view atIndex:0];
[currentView.view setFrame:CGRectMake(0, 0, 1024, 768)];
Some people online say that if you are using ios5 or later, it's ok, but others say "NO NEVER DO THIS!!!" even if it's ios5. Others say to use container views, but in every tutorial I've seen to use a container view you just end up inserting the view controller as a subview to the main view anyway using this after you've inserted the child view:
[self.view addSubview:self.currentView];
I am not using a Navigation Controller because they have limited customizability and I do not want any stock tab bars or navigation bars, just all custom buttons.
Thanks in advance!
Yes of course, it's how UINavigationController works and how UITabBarController works. Interface Builder will event set it up for you with a container view.
see Creating Custom Container View Controllers
The takeaway is it's important to handle childViewControllers. This can get a bit tricky, but is important for notifications to propagate correctly.

iOS7 - content overlapping during push segue from table view

Apologies if this has been asked before. I can't find any reference to this particular problem though.
I have an app which is basically a table view nested within a navigation controller. Each item from the table segues to a fresh view (via a generic push transition), containing some content within a scrollview. I have set this all up using storyboard for ease of layout.
When you click an item in the table, the intention is for the table to slide off the screen to the left and be replaced by the content view. This works fine in iOS 6, but since testing the app on iOS 7 I've noticed the functionality is different.
In iOS 7 the content view slides into frame as normal, but the table view only slides a little way to the left - still visible behind my new content. It disappears very suddenly after half a second or so, but the effect is very jarring as it creates a momentary overlap of two views.
This is only a problem because my content views have transparent backgrounds, but this is important to maintain for the effect I want. So just to be clear, my content view slides in over the top of the menu, which subsequently disappears. Looks very odd.
Any help on this would be much appreciated. I'd be curious to know the reason for this change and if there's a way I can fix it. Preferably by making the menu slide all the way offscreen again.
Thanks!
I had the same problem.
Try to add into target ViewController (that shows up after push)
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor redColor];
}
If all is ok you can change background to something like that
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"GreenBkg.png"]];
ps. tableView needs to be defined as #property in your .h filw

A view in UITabBarController disappears after a memory warning

I have a UINavigationController within one of the tabs of a UITabBarController.
I now present a new view controller (let’s call it Steve) over the whole app (using presentViewController:animated:completion:).
Then, I simulate low memory.
After dismissing Steve (using dismissViewControllerAnimated:completion:), I can now see that the UINavigationController’s view is gone; within the tab; only an empty white area is seen!
Why is this? I have tried calling the view methods on all imaginable controllers upon Steve’s dismissal, but the contents of the tab still stay empty (white).
The strange thing is this: If I click on another tab, and click back on the original tab, the contents (the navigation controller) shows just fine again. Is the tab bar controller doing something special to force the view to display?
UPDATE: I was able to “fix” my issue with this terrible code, just before dismissing Steve:
[[[[[self tabBarController] view] subviews] objectAtIndex:0]
addSubview:[[self navigationController] view]];
What this does is that it finds the subview of the tab bar controller which is not the tab bar (i.e. the top view), and then adds the navigation controller’s view to be its subview.
This is of course terrible, because it makes internal assumptions about the subview structure of the tab bar controller’s view.
If someone has any better solutions, please let me know about them.
When your app receives a memory warning, one of the first thing it will do is drop the view hierarchies of any view controllers that have loaded views but are not currently visible (like your UINavigationController). Most likely, whatever view controller is at the top of your navigation stack is having its views dropped but not reloading them when it reappears.
Always put your view construction code in -loadView or -viewDidLoad and not in -init. That way, the view controller will reconstruct your view if it's been dropped due to a memory warning.
(P.S.: The reason your hack works is the bit where you call [[self navigationController] view], which in turn calls -loadView on the top VC in the stack, forcing it to reconstruct its view.)

How to clear or resetting UINavigation history?

I have a game setup screen which uses UINavigation and am trying to reset or clear the UINavigation once a person has selected a color.
My app's current process can be best described in the following diagram:
Start application -> New game -> Pick character -> Pick Color -> Start game
Up until "Pick Color" I use the UINavigation, however when a color is picked I want to clear the UINavigation history.
The reason for doing this is so that you can't go back once you've started the game and want the UINavigation to with a clean slate with no indication that you can go back (and this also includes going back to the main menu screen).
The way I am doing it right now is thusly;
[self.navigationController popToRootViewControllerAnimated:YES];
GameDashboardVC *dashboard = [[GameDashboardVC alloc] initWithNibName:#"GameDashboardVC" bundle:nil];
dashboard.title = #"Dashboard";
dashboard.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:dashboard animated:YES];
[dashboard release];
The problem is that it pops to the rootViewController but it never pushes the dashboard onto the stack.
I've tried:
[self.parentViewController.navigationController pushViewController....]
The only thing I haven't tried is putting my dashboard push inside the root view controller itself, but I am concerned because I am not sure if it should even be there.
Therefore, where is the correct place to put this kind of functionality, and how do I clear the UINavigation's stack.
Thank you for your time/help.
I solved the problem now to my satisfaction.
I put the following code inside my initWithNibName method:
self.navigationItem.hidesBackButton = YES;
This hid the back button and I didn't have to pop anything, but I think for memory reasons it might be useful to keep the idea of removing un-necessary items from the stack.
But for now the above will do.
If you want reset the UINavigation History, reinitialise the navigation controller.
if you using UINavigationController from AppDelegate class. You can reinitialise the navigation history.
appDelegate.navigationController=[[UINavigationController alloc]init];
Above code will reset the navigationController history..

what am I doing wrong in attempt to popup a web view and then allow user to go back

my app has tabBarController with 3 views and in one of them I want to popup a web browser with the ability to return back to the application. To do that I am using UINavigationController.
In myAppDelegate.h I have defined the property UINavigationController *nav and in myAppDelegate.m I have #synthesize nav.
In the class where the webPopup function resides upon pressing the button my code comes to this function.
- (IBAction)showWeb:(id)sender {
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
// because I want to return back to the same view
webController *web = [[webController alloc] initWithStyle:UITableViewStypeGrouped];
[app.nav pushViewController:web animated:YES];
app.nav.view.frame = CGRect(,0,320,430);
[self.view.window addSUbview:app.nav.view];
}
The web popup occurs but it is moved vertically, when I press "back button" my former view appears as well and it is also shifted vertically from what it was before.
After going back and forth few times the thing hangs.
Questions:
1. what can cause the shift?
2. how to avoid when I go "back" to see the title(test from the "back"button, I think this might cause a shift when I go back.
3. how to find out why it hangs after few attempt?
Thanks.
Victor
The line:
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
makes no sense to me. Surely your compiler is warning you about that? What is "myAppDelegate" defined as? Classes should have a capital letter at the front, by the way.
Also, the line
[self.view.window addSUbview:app.nav.view];
is highly suspect, because the UIWindow for your application should have only one child UIView. You shouldn't just add more views willy nilly and expect things to work. It is possible to change the child UIView by removing the old one and adding a new one, but you don't seem to be doing that. Having more than one child UIView of UIWindow gets you into trouble very quickly -- for example, device orientation changing can break.
I'm not exactly clear as to why the app delegate (or the window for that matter) needs to be messed with at all to do what you are trying to do. Sounds like you should just be using standard Nav View Controllers and Web Views.
Also, you are alloc init'ing w/o any memory management.