开发者

iphone view load problem

开发者 https://www.devze.com 2023-01-26 11:30 出处:网络
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 agai

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消