【问题标题】:message sent to deallocated instance 0x9553970? on setting delegate of UITabbarController发送到释放实例 0x9553970 的消息?关于设置 UITabbarController 的委托
【发布时间】:2014-07-21 04:19:40
【问题描述】:

在我的 iOS 应用程序中,我正在使用 MainViewController.m 中的以下方法将一个选项卡栏控制器替换为 rootview 控制器中的另一个选项卡控制器

//Set Tab Bar View as per the Analyst User
-(void)setTabrViewforAnalyst{
    tabBarController_main = [[UITabBarController alloc] init];
    // Create initialized instance of NSMutableArray to hold our UINavigationControllers
    NSMutableArray *tabs = [[NSMutableArray alloc] init];

    tabBarController_main.delegate=self;

    // Create first UIViewController

    PlannedEventViewController *plannedView=[[PlannedEventViewController alloc]initWithNibName:@"PlannedEventViewController" bundle:nil];
    UINavigationController *plannedNavigationView=[[UINavigationController alloc]initWithRootViewController:plannedView];

    // Initialize the UINavigationController

    [tabs addObject:plannedNavigationView];

    MyVideoViewController *videoView=[[MyVideoViewController alloc]initWithNibName:@"MyVideoViewController" bundle:nil];
    UINavigationController *videoNavigationView=[[UINavigationController alloc]initWithRootViewController:videoView];
    // Add UINavigationController to you tabs
    [tabs addObject:videoNavigationView];


    MyTeamViewController *myTeamview=[[MyTeamViewController alloc]initWithNibName:@"MyTeamViewController" bundle:nil];
    UINavigationController *myTeamNavigationView=[[UINavigationController alloc]initWithRootViewController:myTeamview];
     // Add UINavigationController to you tabs
    [tabs addObject:myTeamNavigationView];


    // Create second UIViewController
    SettingViewController *settingView=[[SettingViewController alloc]initWithNibName:@"SettingViewController" bundle:nil];
    UINavigationController *settingNavigationView=[[UINavigationController alloc]initWithRootViewController:settingView];

       settingView.isLoggedIn=YES;
    // Add UINavigationController to you tabs
    [tabs addObject:settingNavigationView];
    // Add the tabs to the UITabBarController



    // Create second UIViewController

    // Add the tabs to the UITabBarController
    [tabBarController_main setViewControllers:tabs];



    tabBarController_main.tabBar.backgroundImage = [UIImage imageNamed:@"tab_back.png"];

    UIImage *selectedImage1 = [UIImage imageNamed:@"my_team.png"];
    UIImage *unselectedImage1 = [UIImage imageNamed:@"my_team.png"];

    UIImage *selectedImage0 = [UIImage imageNamed:@"events.png"];
    UIImage *unselectedImage0 = [UIImage imageNamed:@"events.png"];

    UIImage *selectedImage2 = [UIImage imageNamed:@"video"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"video.png"];

    UIImage *selectedImage3 = [UIImage imageNamed:@"settings.png"];
    UIImage *unselectedImage3 = [UIImage imageNamed:@"settings.png"];


    UITabBar *tabBar = tabBarController_main.tabBar;
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
    UITabBarItem *item3 = [tabBar.items objectAtIndex:3];


    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
    [item2 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
     [item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];

    item0.title = @"a";
    item1.title = @"b";
    item2.title=@"c";
    item3.title = @"d";

    //Check OS version
    NSString *strOsVersion = [[UIDevice currentDevice] systemVersion];
    float osVersionFloat = [strOsVersion floatValue];

    if (osVersionFloat >= 7.0)
        tabBar.translucent = false;

    tabBar.tintColor = [UIColor colorWithRed:234.0/256.0 green:234.0/256.0 blue:234.0/256.0 alpha:1.0];
     [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_selected_blue2.png"]];

    tabBarController_main.selectedIndex=3;

    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    app.window.rootViewController = tabBarController_main;


}

但是当我在 MainViewController.m 中将 UITabBarControllerDelegate 的委托设置为 self 时,我正在创建标签栏,它会使应用程序崩溃并出现错误 [MainViewController respondsToSelector:]: message sent to deallocated instance 0x9553970 谁能告诉我应该是什么问题? tabBarController_main 是我的 .h 文件的属性

【问题讨论】:

  • 谁在坚持MainViewController
  • 我不明白你的意思..

标签: ios objective-c delegates uitabbarcontroller


【解决方案1】:

问题在于,要么您已在预期之前释放了您的MainViewController,要么是其他东西意外释放了它。您可以在[-MainViewController dealloc] 中放置一个断点,然后在调试器中停止并检查堆栈以了解它发生的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 2016-08-28
    • 2011-06-16
    • 2013-08-30
    相关资源
    最近更新 更多