when run this (controller is a uitableviewcontroller)
[self.navigationController pushViewController:controller animated:YES];
it always has a line between the tableviw and navigationbar.
look like this:
why? and how to hide the blank?
Related
I have been searching around about this problem, but haven't got any answer yet. My problem is: I have a push button that when clicked will push to another view.
Here is how I push it:
ViewController *vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]
instantiateViewControllerWithIdentifier:#"Main_View"];
[self.navigationController pushViewController:vc animated:YES];
The ViewController vc is the view that I pushed. So in the new view, there is a Back button that can drop the current view and comeback to the old view. When I click the push button, the vc been load again from allover.
How can I make the instance of vc stay in memory, so when I go back to old view and come to vc again, it doesn't need to reload again?
I guess it is something related to navigationController stack, but don't know how to do that.
Thanks
Just keep a ViewController instance as property in your first ViewController
#property (strong,nonatomic)ViewController * vc;
Then when push it,check if it is in memory
if (self.vc == nil) {
self.vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]
instantiateViewControllerWithIdentifier:#"Main_View"];
}
[self.navigationController pushViewController:self.vc animated:YES];
Are you using a UINavigationController? If so, can call the following line of code in you back button 'IBAction':
[self.navigationController popViewControllerAnimated:YES];
If you really need to keep a instance of the view controller, do what Leo suggested.
I have a login screen after which home screen is shown. In home screen ,there are four buttons a,b,c,d. On pressing each button, say view a,b,c,d should appear related to view controller a,b,c,d. All these views are embedded in a UITabBar controller. The problem now is when I use the code
[self.tabBarController setSelectedIndex:2];
nothing happens and no view appears. How do i open the view using selected index method or any other method?
Thank You
Found the answer finally. Instead of
[self.tabBarController setSelectedIndex:2];
Use
UITabBarController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierFromStoryboard"];
[self.navigationController pushViewController:controller animated:NO];
[controller setSelectedIndex:2];
This would work fine.
In my app I have an ECSlidingViewController declared as initial root controller via Storyboard. In my AppDelegate's didFinishLaunchingWithOptions method, I instantiate it as above:
self.slidingController = [[UIStoryboard storyboardWithName:#"AppStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"ECSlidingViewController"];
What I want is to be able to show a global modal view controller (eg. when a push notification arrives while the app is active) without knowing which controller is currently top in the sliding controller.
What I do is (in my AppDelegate):
[self.slidingController.topViewController presentModalViewController:controller animated:YES];
but it doesn't seem to work.
Is there any way I could present a modal controller from my sliding controller regardless which controller is topViewController?
PS. If no, is there any chance that what I want will work with SWRevealViewController instead of ECSlidingViewController? If it's worth, I will take the painful road to switch.
Thank you in advance!
If the ECSlidingViewController is set as the initial view controller in the storyboard, then why are you instantiating another one in your app delegate code? By doing that, you're calling your methods on a different instance of ECSlidingViewController than the one that's put on screen by the storyboard. This is likely the source of your problem. Instead, get a reference to your ECSlidingViewController like this:
self.slidingController = self.window.rootViewController;
Then try,
self.slidingController.topViewController presentModalViewController:controller animated:YES];
or
self.slidingController presentModalViewController:controller animated:YES];
I haven't worked with ECSlidingViewController, so I don't know which of these might work.
Try this
UIViewController *rootViewController = self.window.rootViewController;
// You now have in rootViewController the view with your "Hello world" label and go button.
// Get the navigation controller of this view controller with:
UINavigationController *navigationController = rootViewController.navigationController;
[navigationController.topViewController presentModalViewController:controller animated:YES];
I have two views which use UINavigationController. I want the second view to "slide" with animation back to the first view when I tap on a custom button. (not the original in navigationbar)
Try something like this on that button action,
[self.navigationController popToViewController:aViewController animated:YES];
or
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] - 2)] animated:YES];
Here aViewController represents the previous view controller. Similarly you can pop to any viewcontroller you want by using a similar code.
[self.navigationController popToRootViewControllerAnimated:YES]; will take you to the root view controller.
So I have a nav controller and I push a view on the screen, a settings view, but I want to remove it out of the hierarchy, so when the new viewcontroller comes onto screen and the back button is pressed it returns it to the main menu.
I tried this:
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:tabBar animated:YES];
But the the viewController is just popped off and the new one is not presented.
You should try to modify the navigationcontrollers view controller array like the following way:
[self.navigationController pushViewController:tabBar animated:YES];
NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
[VCs removeObjectAtIndex:[VCs count] - 2];
[self.navigationController setViewControllers: VCs];
Maybe the animation will be broken. If this happens you should move the part with the modification of the navigationcontroller VC array to the presented VC's viewDidAppear method.
The problem is that self is released as soon as you call popViewControllerAnimated:. The push call then sends a message to nil.
You could assign self.navigationController to a local variable first, and use that for pushing and popping instead.
Alternatively, and it's a bit of a hack, but before this, you could call [[self retain] autorelease] to give it an extra retain so that it won't disappear until the end of the run loop.