Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:14:58+00:00 2026-06-12T08:14:58+00:00

I have a UITabBarController with two tabs. TAB A is a UIViewController, and TAB

  • 0

I have a UITabBarController with two tabs. TAB A is a UIViewController, and TAB B is a UIViewController loaded from a nib.

I’m trying to make it that when i move from TAB B to TAB A, or from TAB B any other tab, I want to reset TAB B to its initial state. I do that by just creating a new one and replacing that in the viewControllers array. The problem is that after I reset the UIViewController I get an error along the lines of “message sent to deallocated instance. It’s usually one of these two errors:

*** -[AddCompetitionViewController isEqual:]: message sent to deallocated instance...
*** -[AddCompetitionViewController retain]: message sent to deallocated instance...

This happens right after I switch from TAB B back to TAB A.

This is the code that I’m using to replace the tab with my attempt to isolate the problem.

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSLog(@"Should Select: %@", viewController);
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"Did Select: %@", viewController);
    if ([viewController class] != [AddCompetitionViewController class]) {
        AddCompetitionViewController *ACViewController = [[AddCompetitionViewController alloc] initWithNibName:@"AddCompetition" bundle:[NSBundle mainBundle] andDancer:self.currentDancer];
        UITabBarItem *ACitem = [[UITabBarItem alloc] initWithTitle:@"Add Comp." image:[UIImage imageNamed:@"Addcomp.png"] tag:0];
        ACViewController.tabBarItem = ACitem;

        NSMutableArray *arr = [[NSMutableArray alloc] initWithArray:self.viewControllers];
        [arr replaceObjectAtIndex:1 withObject:ACViewController];
        [self setViewControllers:arr];
        NSLog(@"Replaced: %@", [arr objectAtIndex:1]);
    }
}

(I am using ARC)

Using the NSLogs, I’ve been able to determine that When I try to switch back to TAB A, the app is trying to reference the old, original UIViewController, and not the new one. tabBarController:didSelectViewController: is the last thing that is called, I don’t have anything coded that references the UIViewController after the replacement. I’ve also tried adding an exception breakpoint, but that just lists a bunch of hex data, then defaults to application main. Here are my logs:

2012-08-18 16:20:05.479 How's My Feisin'[4780:c07] Should Select: <AddCompetitionViewController: 0x78a5af0>
2012-08-18 16:20:05.489 How's My Feisin'[4780:c07] Did Select: <AddCompetitionViewController: 0x78a5af0>
2012-08-18 16:20:06.885 How's My Feisin'[4780:c07] Should Select: <CompetitionListViewController: 0x78a7550>
2012-08-18 16:20:06.887 How's My Feisin'[4780:c07] Did Select: <CompetitionListViewController: 0x78a7550>
2012-08-18 16:20:06.887 How's My Feisin'[4780:c07] Replaced: <AddCompetitionViewController: 0x6c5d0f0>
2012-08-18 16:20:09.290 How's My Feisin'[4780:c07] *** -[AddCompetitionViewController retain]: message sent to deallocated instance 0x78a5af0

And a backtrace:

* thread #1: tid = 0x1c03, 0x017cddee CoreFoundation`___forwarding___ + 206, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x017cddee CoreFoundation`___forwarding___ + 206
frame #1: 0x017cdcb2 CoreFoundation`_CF_forwarding_prep_0 + 50
frame #2: 0x0176e2c0 CoreFoundation`CFRetain + 96
frame #3: 0x01798ab9 CoreFoundation`CFArrayApplyFunction + 57
frame #4: 0x0072ffbb UIKit`_afterCACommitHandler + 255
frame #5: 0x0183b99e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #6: 0x017d2640 CoreFoundation`__CFRunLoopDoObservers + 384
frame #7: 0x0179e4c6 CoreFoundation`__CFRunLoopRun + 1174
frame #8: 0x0179dd84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #9: 0x0179dc9b CoreFoundation`CFRunLoopRunInMode + 123
frame #10: 0x01c447d8 GraphicsServices`GSEventRunModal + 190
frame #11: 0x01c4488a GraphicsServices`GSEventRun + 103
frame #12: 0x0071f626 UIKit`UIApplicationMain + 1163
frame #13: 0x00002595 How's My Feisin'`main + 181 at main.m:16
frame #14: 0x000024d5 How's My Feisin'`start + 53

Any help figuring out this error, or finding a better place to replace the UIViewController would be great!
Thanks!

EDIT: I have found what is causing the issue, but still don’t have a way to fix it. Even though I’ve never seen a UITabBarController animate a view change, It apparently still preforms an animation. I managed to profile the app, and _afterCACommitHandler is preforming an extra release on the object.

EDIT: I’ve figured out a work around, I put another UIViewController between the tabBarController and the UIViewController for TAB B. Then had the new UIViewController reset the old one. It works, but it’s not the right way to do things. And I still don’t know what was causing the extra release.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:15:00+00:00Added an answer on June 12, 2026 at 8:15 am

    I created a workaround that encapsulates the UIViewController for TAB B in another UIViewController. This intermediary controller is the delegate for the UITabBarController, and deallocates and recreates the UIViewController I want to reset on a tab change. This prevents a missing ViewController reference in the tab bar controller.

    Here is the intermediary class:

    .h file

    #import <UIKit/UIKit.h>
    #import "AddCompetitionViewController.h"
    #import "Dancer.h"
    
    @interface AddCompResetViewController : UIViewController <UITabBarControllerDelegate>
    {
        BOOL willReset;
    }
    
    @property (nonatomic, retain) Dancer *currentDancer;
    @property (nonatomic, retain) AddCompetitionViewController *ACViewController;
    
    - (id)initWithDancer:(Dancer *)dancer andTabBarController:(UITabBarController *)aController;
    @end
    

    .m file

    @implementation AddCompResetViewController
    @synthesize currentDancer, ACViewController;
    
    - (id)initWithDancer:(Dancer *)dancer andTabBarController:(UITabBarController* )aController;
    {
        if ((self = [super init])) {
            self.currentDancer = dancer;
            //create first instance
            self.ACViewController = [[AddCompetitionViewController alloc] initWithNibName:@"AddCompetition" bundle:[NSBundle mainBundle] andDancer:self.currentDancer];
            self.ACViewController.theTabBarController = aController;
            [self.view addSubview:self.ACViewController.view];
            willReset = NO;
        }
        return self;
    }
    
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
        //reset
        if (viewController != self) {
            AddCompetitionViewController *AViewController = [[AddCompetitionViewController alloc] initWithNibName:@"AddCompetition" bundle:[NSBundle mainBundle] andDancer:self.currentDancer];
            [self.ACViewController.view removeFromSuperview];
            self.ACViewController = nil;
            self.ACViewController = AViewController;
            [self.view addSubview:self.ACViewController.view];
            willReset = NO;
        } else if (viewController == self) {
            willReset = YES;
        }
    }
    
    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
        if (viewController.tabBarItem.tag == 4) {
            [self.navigationController popToRootViewControllerAnimated:YES];
            return NO;
        } else {
            return YES;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have UITabBarController that has two tabs .Every tab load a file from internet
I have an UITabBarController with two tabs: UINavigationController OptionsViewController : UIViewController How can I
I have an application that has a UITabBarController with two tabs, each having its
I have a UITabBarController, and each tab handles a different UIViewController that pushes on
I have a UITabBarController that manages two ViewControllers. The first is a UIViewController that
HEllo, I have a hybrid iPhone application that has a UITabBarController and 5 Tabs.
I have a UITabBarController that manages 5 View Controllers. I create their tab bar
I have a UITabBarController with three tabs, each is a UIViewController with a UITableView.
I have a main UIViewcontroller (vcMain) with two UIViewControllers subclassed from the main one.
i have uitabbarcontroller with two uiviewcontroller. i want to know if there is possibility

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.