positioning problem with uisplitviewcontroller in left view - objective-c

i got a little problem, when launching my splitview in landscape, there is a little black space above my left view controller:
after rotating my ipad to portrait and switching back to landscape, the space is gone.
if i load the uitableviewcontroller directly into the left view, and not in a navigationcontroller, it works fine:
any ideas why this is happening ??
// Produkte
self.produkteMainTableVC = [[produkteMainTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *produkteMainNavigationController = [[UINavigationController alloc] initWithRootViewController:self.produkteMainTableVC];
self.produkteDetailVC = [[produkteDetailViewController alloc] initWithNibName:#"produkteDetailViewController" bundle:nil];
self.produkteSplitVC = [[UISplitViewController alloc] init];
self.produkteSplitVC.delegate = self.produkteDetailVC;
self.produkteMainTableVC.produkteDetailVC = produkteDetailVC;
[self.produkteSplitVC setViewControllers:[NSArray arrayWithObjects:produkteMainNavigationController,self.produkteDetailVC,nil]];
thanks for all help!
edit:
its exactly 20px like the statusbar. does that help anyone?
edit2:
doing something like this:
if(self.navigationController.navigationBar.frame.origin.y >= 20.0) {
self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
}
results that:
a little improvement i would say. but i have no idea how to stick my tableview underneath the navigationbar.

I know this is a very old topic but maybe it'll help other people...
I had the same issue (with the same configuration : splitview in tabbar).
This property solved it !
[self.splitViewController setWantsFullScreenLayout:YES];

UINavigationController has a nasty habit of shifting its contents down by 20px, depending where you place it. I'm guessing it's doing it here because your split view controller is inside of a tabbar controller, and Apple has not blessed this type of arrangement.

I've run into this same issue, with out a resolution. The only thing I've noticed is this does NOT happen when the master does not include a UINavigationController as its root.
Anyone figure a solution to this?

Here's what I did, and it seems to work fine.
I created my own custom tab-view controller, derived from UIViewController. In viewDidLoad I add a UITabBar to the bottom of the view and set the delegate to myself so I can handle tab changes. (I return this UITabBar as the rotatingFooterView) Tab changes result in swapping the current view controller, just like a real UITabBarController. When swapping view controllers (sometimes a UISplitViewController, hosting a UINavigationController in the master view), I add and position the view-controller's view within my view, above the UITabBar. I'm also careful to forward viewWill/DidAppear/Disappear calls to the current view controller, as well as each of the will/didRotate messages.

seems that this problem occurs from iOS 7.0. Setting the frame of UINavigationBar in some cases doesn't work. I think this can solve your problem :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
self.navigationController.view.frame = CGRectMake(0, -20, self.navigationController.view.frame.size.width,
self.navigationController.view.frame.size.height);
}
This code should be called only once (for example in - (void)viewDidLoad ).
In my case it works for all device orientation.

Related

Why is the top of a view controller presented in a UIPopoverController cut off?

My app presents a view controller inside a UIPopoverController when the user presses a button. On iOS7 this works fine, but on the iOS8 beta the top of the view controller is underneath the popover's navigation bar. You can see the difference in the screenshots below.
I've made a really simple app that shows the problem. There's one button connected to the method shown below. contents is a very simple view controller with a yellow background and two labels in it. thePopoverController is a UIPopoverController.
- (IBAction)go:(id)sender {
self.contents = [[ContentsViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:self.contents];
self.thePopoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
[self.thePopoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:TRUE];
}
Does anyone know why this happens on iOS8? Is there a way of getting it to work on iOS7 and 8, without having to hard-coded an offset? Any help much appreciated!
Cheers
I had this issue and removing UIRectEdgeTop from my view controller's edgesForExtendedLayout mask fixed it for me. So after setting self.contents, do this:
self.contents.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;

UIwebview verticall scrolling not working

I add webview and navigationbar inside my view controller .
Web view is display properly but when I am start to drag scroll vertically that webview and stop dragging, uiwebview reach in top.
In short, Scrolling is not working in vertically.
here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
web.delegate=self;
NSBundle *myAppBundle = [NSBundle bundleForClass:[self class]];
NSString *htmlFilePath = [myAppBundle pathForResource:#"infotext" ofType:#"htm"];
[web loadHTMLString:htmlFilePath baseURL:nil];
[self.view addSubview:web];
}
Here I take webview inside IB and set it outlet.
Either you have webview.userInteraction = NO which disables the scrolling in the webView or you have added the webview to the wrong view as a subview.
Try First adding this above your addSubview : web.userInteractionEnabled = YES;
If that doesn't work then you need to look at which viewController all this code is from. In order for this to work since you are using a UINavigationController, you need to make sure this code is happening in the RootViewController and the NavigationController as well as the RootViewController are wired up correctly.
It sounds like you just drug over a Navigation Bar from IB which won't really do what you are hoping for in this case so its probably likely that its causing your issues.

presentModalViewController gives a black screen

In an alert view method I implemented the following (pretty standard) piece of code for popping a modal view:
else if (buttonIndex == 1) {
EmergencyPlanViewController *emergencyPlanView = [[[EmergencyPlanViewController alloc] init] autorelease];
[emergencyPlanView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:emergencyPlanView animated:YES];
}
Somehow it gives me a black screen as result. I can't find what is wrong here.
I created the window in my MainStoryBoard and customized the class of the viewcontroller in IB to EmergencyPlanViewController.
The viewDidLoad method of the emergencyPlanView is triggered but it looks like the view is not loaded. Anyone an idea what's wrong here?
EDIT:
To be clear, I am not using seperate xib-files in my project. I only use the storyboard
In the xib file, is your UIView set to the File Owner's view. That is probably the problem. Also if you just apply init, that will load the EmergencyPlanViewControllerinterface builder file with the same name:
EmergencyPlanViewController.xib
So make sure in that case that either:
The EmergencyPlanViewController nib is indeed: EmergencyPlanViewController.xib
or that you write instead of init: initWithNibName://whatever nib name here
I managed to fix the black screen issue when presenting a modal view controller by setting a background color to the view in Interface Builder. I noticed that by default the background color of the view is set to something like black/white (see picture attached), although it appears in white. I don't know exactly what does this mean or how it is responsible for showing a black screen, but setting a single color or texture fixed it. PS: I've faced this when migrating from iOS SDK 5 to 6.
ios6
Try this:-
EmergencyPlanViewController *emergencyPlanView=[[EmergencyPlanViewController alloc] initWithNibName:#"EmergencyPlanViewController" bundle:nil];
emergencyPlanView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:emergencyPlanView animated:YES];

Trying to dismiss subview and UIView

I'm still very new to iOS developing. In fact, if there is a super noob, I would be one :p. Currently I am working on creating an IBAction button that accesses a subview. I have 2 ViewControllers, AddClientVC and NewClientVC, both with .nib files. So basically, inside my AddClientVC I implement an IBAction button with the following code:
- (IBAction)buttonPressed:(id)sender
{
UIView *transparentBG = [[UIView alloc] initWithFrame:CGRectMake(-5, -5, 1500, 2500)];
transparentBG.backgroundColor = [UIColor blackColor];
transparentBG.opaque = NO;
transparentBG.alpha = 0.5;
[self.view addSubview:transparentBG];
transparentBG.center = transparentBG.center;
vc = [[NewClientVC alloc] initWithNibName:#"NewClientVC" bundle:nil];
[self.view addSubview:vc.view];
vc.view.center = self.view.center;
}
As you can see I implemented a UIView as a transparent background. Basically AddClientVC --> Transparent Background --> NewClientVC. Now I have created another IBAction button but this time inside NewClientVC as a function to dismiss the accessed subview which looks like this:
- (IBAction)saveDismiss:(id)sender
{
[self.view removeFromSuperview];
}
The problem I'm having right now is when I click the saveDismiss button it only removes the subview that I called previously on AddClientVC but it didn't remove the transparent background I have created as a UIView. So the problem is how do I implement an action which simultaneously removes my subview and the UIView transparent background I created.
I need all the help I can get :)
I'm not too sure I fully understand what you want to happen, but maybe you could try something like this?
- (IBAction)saveDismiss:(id)sender
{
[vc removeFromSuperView];
[self.view removeFromSuperview];
}
I recommend not to manage your screens by adding subviews manually but instead use
- (void)presentModalViewController: (UIViewController *)modalViewController
animated: (BOOL)animated
method on your root viewController.
Or better instantiate a UINavigationController and use push and pop methods to drill down/up your views.
See apple reference here
Do not worry about code execution speed and stay confident in apple's SDK. UIKit is optimized for best user experience. Trying to boost your code by doing inappropriate SDK use is, in my opinion, a risky strategy. ;) – Vincent Zgueb
Sorry Vincent but I don't agree with you. I reached here because I want to implement an gesture that adds a sub-view for my view, which will be the navigation of my app.
[self.view addSubview:ctrl.view];
is faster presenting the view than
[self.navigationController presentModalViewController:ctrl animated:NO]
and by the way, the solution to the topic in my case was:
[self.view sendSubviewToBack:ctrl.view];

Adding a Navigation Controller to a View based Application adds top margin

I am trying to programmatically add a Navigation Controller to my View based Application. This is the code I am using (this code gets called after a button press in a view controller):
MainMenu *control = [[MainMenu alloc] initWithNibName: #"MainMenu" bundle: nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
[self.view addSubview:navControl.view];
[control release];
That works, but this ends up happening:
Notice the odd margin above the Navigation control.... My View controller that I am adding the Navigation Controller to has a gray background which you can see.
Any ideas??
If you have a better way of adding a Navigation Controller to a View based Application I am very open to suggestions!
Thank you in advance!
Thank you both for your response, but unfortunately, wantsFullScreenLayout set to YES or NO in the code didn't have any effect. I was able to push the Navigation Controller up by 20 using this line of code:
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);
but then what happened was that the View Controller did not move up with the Navigation bar and left a gap below the Navigation Bar and the View Controller. What eventually worked was checking the Wants Full Screen checkbox in IB in the MainWindow view controller that is automatically generated when you set up a view based application.
The gap you are seeing is the same height as a status bar. Check the status bar settings in your NIB file.
Chances are you want to make the UINavigationController the root view controller for the window, rather than whichever view controller you have now. That would be the better way to do it.
The reason you're seeing that extra margin at the top is because UINavigationController normally expects that it will be sized to fill the entire screen (except perhaps a tab bar at the bottom, if it's inside a UITabBarController), and therefore expects that the top edge of its view will be under the status bar if the status bar is visible. Therefore, it places its navigation bar 20 pixels below the top of its view to leave space for the status bar, without bothering to check whether its view actually is under the status bar. Interestingly, sometimes a re-layout operation will perform this check, but that's unreliable. What I've found works well in a situation like this is to set the UINavigationController's wantsFullScreenLayout property to NO. Then ti doesn't try to leave room for the status bar, so everything works as expected.
I've been struggling with this same issue this morning. Since setting the wantsFullScreenLayout property doesn't seem to have any effect, I resorted to using a little subclass, which worked fine:
#interface MyNavigationController : UINavigationController
#end
#implementation MyNavigationController
- (BOOL)wantsFullScreenLayout;
{
return NO;
}
#end
Its so simple to remove that gap..
self.navigationBar.view.frame = CGRectMake(0, -20, 320, 480);