I have a UITabBarController in which I have 3 UIViewControllers (3 tabs).
I want to remove specific elements from each UIViewController view when the whole UITabBarController will disappear.
Is there any way to do this? I cannot use viewWillDisappear: in each UIViewController because this will remove these elements when the tab changes also.
Is there any way to handle this into viewWillDisappear: into TabBarController.m file?
You will be taking reference of viewController getting displayed. Use those references on back button to remove your specific elements from your controllers.
Hope you get it. Feel free to ask if any concerns ?
Or, you can use these delegate methods of UINavigationController :
// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
Related
I need to pass an object to the root view controller of an UINavigationController before it appears. I have its root view controller relationship set in storyboard, and it seems that I can't handle it like the other types of segues.
How could I do this?
Thanks
You could assign the UINavigationController a delegate and implement the method -
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
// check viewController is kind of class, check any flags
// pass object to vc
}
I have the following VC hierarchy: ParentViewController -> Navigation Controller(child VC) -> ViewController(with UITableView).
I am meeting the following issue:
In UITableViewDelegate.didSelectRowAtIndexPath, the app is pushing a new ViewController on the stack. The problem is that at this stage, the table view is automatically reloaded, without any explicit call to reloadData. This fact creates several issues, for example on return to the screen(with Back button) the table view is scrolled at the beginning instead of being focused on the selected row.
Could you please help me find why is it doing like so, is it a bug, or how to fix the issue?
UPDATE: I have just tested the same case on iOS 7.1 and there is no issue like that, I mean pushing a viewController, than poping back to the viewController containing the UITableView does not loose focus of the selected row.
hope this could help you.
My solution is to use navigationviewcontroller delegate, save selection when will push another one, and set back when pop back.
My sample code(I have set table view controller as delegate)
static NSIndexPath* path = nil;
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self)
{
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
path = self.tableView.indexPathForSelectedRow;
}
I'm having a problem with EGOPhotoView library in my iOS app, and I hope someone of you can help me.
My app uses a NavigationController, but does not display the NavigationBar, because the navigation is managed my some custom control. The problem is when I show an image gallery with the EGOPhotoView library, which shows a NavigationBar appearing on tap: when I pop the EGOPhotoViewController, the NavigationBar is still displayed, but I don't want.
Can someone help me to fix this problem?
Thanks
You can set one of your classes (probably your app delegate) to be the navigation controller's delegate. Then, when the EGOPhotoViewController is popped, you can hide the navigation bar. E.g.
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([navigationController.topViewController isKindOfClass:[EGOPhotoViewController class]])
{
[navigationController setNavigationBarHidden:YES animated:YES];
}
}
I'm running into what seems like buggy behavior. I have one UINavigationController, which contains a tabBarController within it. That tabBarController has more than 5 tabs, so there is a more button, which loads the MoreController navigationController. Of course, that creates nested navigationControllers, so I want to hide one of the navigationBars.
I do that by making my ApplicationDelegate a UINavigationControllerDelegate:
[[tabBarController moreNavigationController] setDelegate:[UIApplication sharedApplication].delegate];
And implementing:
(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
navigationController.navigationController.navigationBarHidden = YES;
}
However, I end up with the Status bar overlapped:
Now, if I add some code to fix the frame manually, there's still some weird color overlay on the status bar, and now a black gap underneath the navigation bar. What gives?
I have 2 view controllers and a tab bar controller created in storyboard.
is it possible to execute a method in either of the 2 view controllers when the relevant tab bar is pressed?
Ive tried several ways but they need a nib name on the firstViewController or secondViewController if I want to initialize an object of the firstViewController, normally the firstViewController is just created on launch,
Any help would be appreciated, I'm vaguely familiar with the uitabcontroller app delegate but I don't know how to hook up the two view controllers to the tab controller
Have a look at the UITabViewController Delegate :
You use the UITabBarControllerDelegate protocol when you want to
augment the behavior of a tab bar. In particular, you can use it to
determine whether specific tabs should be selected, to perform actions
after a tab is selected, or to perform actions before or after the
user customizes the order of the tabs. After implementing these
methods in your custom object, you should then assign that object to
the delegate property of the corresponding UITabBarController object.
All of the methods in this protocol are optional.
Reference : http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
What you need should be achievable by implementing :
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
If you are using storyboard, do this
in didFinishLaunchingWithOptions
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];
And then
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//Write your code here
}