iphone view load problem - iphone

hii, there
I am making a tabbar application.In this application on the first tab I am using navigation so when I navigate to other view and instantly than I goes to other tab. And again when I am going to first tab it show me navigate view I want to show first tab view.
Somebody can tell me how can I manage these things..

Are you asking how to switch from one tab to another in code? If so it looks like this:
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = [yourIntegerIndexHere];
Where it says "YourAppDelegate," obviously use the name of your actual app delegate.
Where it says "yourIntegerIndexHere," that's an integer with the index of the tab you want to switch to. The left-most tab is 0.

Thats the main purpose of the tabbased application that all your views are saved till they are navigated.
If you want the initial view to be there when you tap on the tabbar then on every tabbars view you have to code for poping your view in the first tab to the rootview controller for that tab.
hAPPY iCODING...

As I understand, you have a NavigationController on your first Tab of your TabBarController and, when you click on the first Tab, you want your NavigationController to go back to its root view controller.
First of all, be aware that this is not the default behavior of a TabBarController and it might be a bit annoying to your users. The user can go back to the rootview of a NavigationController inside a TabBarController by tapping the tab a second time.
Knowing this, if you still want to change the default behaviour of your TabBarController, here is what you can do :
Set your AppDelegate class to be the Delegate of your UITabBarController. It has to implement the UITabBarControllerDelegate protocol, and you have to write something like this :
[myUITabBarController setDelegate:self];
inside your application didFinishLaunchingWithOptions: method.
Then, implement this method inside your AppDelegate.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([tabBarController selectedIndex] == kMyNavigationControllerIndex) {
[(UINavigationController *)[tabBarController selectedViewController] popToRootViewControllerAnimated:NO];
}
}
Where kMyNavigationControllerIndex is a constant value containing the index of the NavigationViewController you want to change (i.e. 0 if it is the first tab).
Hope this helps.

Related

Tab bar gets covered by the new view

I have built an app based on a tab bar controller. While I am on one of the tab views I want to be able to swipe my finger and switch to another tab view of which the index on the tabBarController in unknown. I am therefore calling the desired viewcontroller from its nib. The view gets swapped correctly but the problem is that it appears ABOVE the tab bar itself, covering it completely and making it become unusable! How can I push the view back or the tab bar up? Thanks
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender
{
DesiredViewController *controllerInstance =[[DesiredViewController alloc]initWithNibName:#"DesiredViewController" bundle:nil];
controllerInstance.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controllerInstance animated:YES];
}
presentModalViewController:animated always uses whole screen: On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.
If you really use UITabBarController, it instantiates view controllers of its tabs. So trying to instantiate view controller of one of tabs manually is wrong. You will end in a mess of view controllers instances.
Set property selectedIndex of your UITabBarController to switch tab. I think you need this. But it will be switched without animation.
If you know only pointer of controller you want to switch to, ask viewControllers property about controller's index and than switch tab by its index:
self.selectedIndex = [[self viewControllers] indexOfObject:viewController];

presentViewController not showing tabbar

I have an iPhone application that uses a tabbar on all my views.
Also, my first view controller has no navigationBarController but my second view does, as well as the tabbar.
My second view controller is a tableview and when I click on one of the cells, I want to be taken to the first view controller (passing along a parameter with it).
I've tried a few ways of doing with, which all kinda work, but don't.
secondViewController.m
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstView" bundle:[NSBundle mainBundle]];
[firstViewController passThisAlong:#"id"];
//[self presentViewController:firstViewController animated:YES completion:nil]; //1
[self.navigationController pushViewController:firstViewController animated:YES]; //2
//[self.tabBarController presentViewController:firstViewController animated:YES completion:nil]; //3
[firstViewController release];
firstViewController = nil;
So as you can see above, I've tried 3 different methods of getting to the first view controller.
The second one loads the first view, drilled down inside the second view, as it keeps the nagigationBarController (even though first view doesn't have one) with the back button to the second view.
The other two do the same thing as each other. Which is it goes to the first view (without a navigationBar), but, there is no tabbar and the content of the first view has been shifted up about the height of the tabbar, and in it's place is just blackness.
I hope this all makes sense. I just want to be able to go from my second view when someone selects a cell in the table, to my first view as if I'd clicked the icons in the tabbar.
I've seen in the docs
'On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.' not sure if this is related to my issue and if so, if there's a way around it.
Many thanks,
It's normal, a modal View is supposed to work this way
From Apple Documentation
The ability to present view controllers is a tool that you have at your disposal for interrupting the current workflow and displaying a new set of views. Most commonly, an app presents a view controller as a temporary interruption in order to obtain key information from the user. However, you can also use presented view controllers to implement alternate interfaces for your app at specific times.
In your didSelectRowAtIndexPath you can use something like
YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 0;
Present modal view works this way. And why can't you use a Tab based application?

Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

I have a UITabBarController setup with 2 UINavigationControllers.
One UINavigationController has One UIViewController, the other UINavigationController has Two UIViewControllers. If you then navigate to the second UIViewController and click the Tab that is already selected it bring you to the root of the UINavigationController (This would be the first UIViewController).
Is there a way to stop this from happening? I do not want the user to be able to click an already selected Tab to go to the root of the Navigation Controller.
To do this you need to implement a function in your app delegate to pick up the tabbar delegate calls.
In your app delegate.m file, in the didfinishlaunching method, add this line
[tabBarController setDelegate:self];
then implement this method (also in your app delegate):
- (BOOL)tabBarController:(UITabBarController *)theTabBarController shouldSelectViewController:(UIViewController *)viewController
{
return (theTabBarController.selectedViewController != viewController);
}
This gets called as part of the tab delegate protocol and will stop the selection of a tab if its already the selected one.
Hope that helps.

iPhone TabBarController - set selected tab programmatically

I have two tabs in my app, each of them is a UITableView, and each of the views in the two tabs has its own DetailViewController.
Now, if I click on a TableViewCell in the DetailViewController in the first tab, I want to jump to the DetailViewController of the second tab. I know how to access the second tab
self.tabBarController.selectedIndex = 1;
and I know how to access the DetailViewController, but only without jumping to the second tab.
Is it possible to access the second tab, and then access its DetailViewController?
It would be best if the main TableView in the second tab wouldn't be visible at all, so, it should jump directly to the DetailViewController of the second tab, with the navigation controller showing the "back" button to the main view controller and the second tab highlighted. Is this possible? And, if it is, how can I do this?
Thanks in advance :-)
The tabBarController has an array with the viewController of every tab. You can push the DetailViewController like this:
[[self.tabBarController.viewControllers objectAtIndex:1] pushViewController:detailViewController animated:NO];
Before that you might want to pop to the rootViewController:
[[self.tabBarController.viewControllers objectAtIndex:1] popToRootViewControllerAnimated:NO];

Tab bar controller

I have the next question:
In my project I have the next:
UItabbarController
....Some UINAvigationControllers....
*(1) UINavigationController
UIViewController (UItableView) - When select one row it goes to...(by push)
UIViewController (UItableView)
My problem is when i click in the tab bar item, I see the viewController view like last time that i saw this, and no reload to the *(1) first view another time.
Where I need to write sth for each time that i click in a tab bar item i reload the first view of this tab bar item.
Thanks!
If I understand your question correctly, you are trying to return the navigation controller to the root element when it's tab bar item is selected.
To do this, set some object (e.g. your application delegate, but it can be some other object instead) to be the delegate for your UITabBarController. (If you use the application delegate, it will be the delegate for more than one thing, which is fine.) Then, implement the tabBarController:didSelectViewController: method. In that method, tell the selected view controller (which should be a NavigationController) to return to the root view controller.
Something like this. Add this implementation to your AppDelegate.m class:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[viewController popToRootViewControllerAnimated:NO];
}
In your .xib file, set the delegate for the TabBarController to the the AppDelegate. (If you are programmatically creating the tabBar, you'll have to do it programmatically there.)
As you suspected, trying to do this in viewWillAppear method, or anything other method, of the view controller that live in the navigation controller is not the correct approach. It is a method to perform on the navigation controller, and detected by the delegate of the tab bar.
Try putting your callback code to reload the view in the viewWillAppear or viewDidAppear methods. These are both called every time a view controller displays it's view on the screen.
Also feel free to copy and paste your actual code, it usually makes things easier on our end :)