ios - 为什么Tabbar选中项总是0?

标签 ios objective-c methods uiviewcontroller uitabbarcontroller

我尝试从另一个类打印此值,但它始终将选定的 tabbar 索引显示为 0

为什么?有没有其他方法可以识别现在选择了哪个选项卡?

在我的第二类tableviewcontroller didselect`方法中我试图打印以下行

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    sharedManager=[Mymanager sharedManager]; 
    sharedManager.navigationBarTitle=[name objectAtIndex:indexPath.row];   
    NSLog(@"%d",self.tabBarController.selectedIndex);

}

但总是显示0

我需要为不同的选项卡使用不同的索引?

我的目的是识别选项卡并调用方法,现在我将其更改为调用四种不同的方法 但是当我创建一个对象并尝试调用方法时它没有显示为什么?

我的 APpdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [NSThread sleepForTimeInterval:5.0];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
      [[NSNotificationCenter defaultCenter] postNotificationName:@"internet connection" object:self];
    dispatch_queue_t connectivityThread = dispatch_queue_create("com.ttt.test.connectivity", NULL);

    dispatch_async(connectivityThread, ^{
        while (true){
            if([GMMConnectivity hasConnectivity])
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"InternetCheck" object:[NSNumber numberWithBool:YES]];
            else
              [[NSNotificationCenter defaultCenter] postNotificationName:@"InternetCheck" object:[NSNumber numberWithBool:NO]];

            usleep(5000000);
        }
    });

    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
  // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
  // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


}
//-(void)recentPages:(NSString *)pageNumber
//{
//    //NSLog(@"%@",pageNumber);
//}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
  // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

最佳答案

试试这个

NSUInteger index = [self.tabBarController.tabBar.items indexOfObject:self.tabBarController.tabBar.selectedItem];    
NSLog(@"Index: %d", index);

关于ios - 为什么Tabbar选中项总是0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16850235/

相关文章:

jquery - 之前的方法 jquery

iphone - UIRefreshControl 问题

ios - Swift UIView Constraint Constant Height Changing时间获取LayoutConstraints警告

ios - 如何在应用程序 ios 中添加带有添加事件选项的自定义日历?

objective-c - 如何为 Mac OS X Bundle 设置图标?

python - 如何在Python中的同一类中的另一个方法中传递一个方法的变量

objective-c - 如何在 xcode 4 中通过一个操作归档多个目标

ios - Twitter 库错误 : Undefined symbols for architecture x86_64:

objective-c - 在终端中使用 "defaults"命令写出复杂的内容

methods - 我怎样才能拥有一个可以在 Groovy 中按名称覆盖的默认参数方法?