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

  • Home
  • SEARCH
  • 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 880921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:10:37+00:00 2026-05-15T12:10:37+00:00

I have a view controller managed in a UINavigationController. My view controller puts up

  • 0

I have a view controller managed in a UINavigationController. My view controller puts up a “loading” screen, and uses ASIHTTP to asynchronously load table data. Then it renders its table, and in each cell there’s an image that it uses ASIHTTP to asynchronously load. When it lands each image, it uses [self.tableView reloadRowsAtIndexPaths] to reload that row, inside which the image is fed to the UIImageView in each row.

Works great. But if I back out of the view before it’s done loading, it crashes.

Where it crashes is in my -tableView:numberOfRowsInSection method, and NSZombies tells me it dies because it’s asking for the -count of an NSArray called self.offers that has been deallocated.

That method looks like this:

-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
 return [self.offers count];
}

Wrapping that return in if (self.offers) made no difference.

My -dealloc releases and sets-to-nil every one of these properties, including both self.offers and self.tableView itself. I even tried setting up a BOOL disappearing property, hitting it with YES in -viewWillDisappear, and hanging conditional behavior off that, but it doesn’t work because viewWillDisappear doesn’t seem to get called! Far as I can tell we’re not getting ANY method called when the navigation bar pops us off.

What do I do about this?

EDIT:

Thanks to @cduhn (who’s bucking for a check!), I did a bunch more looking at this. The problem has been, my -dealloc just isn’t getting called when I pop this viewcontroller (nor my -viewWillDisappear nor -viewDidUnload or anything else I could use to unhook the delegation structure that’s at the root of this problem).

Then I realized: THIS viewController isn’t the one on the NavController stack! What’s at the top of the stack right here is a shell view, just a segmented controller and a big empty UIView. I toggle the contents of that UIView between two other UIViewController subclasses depending on the state of my segmented controller. So when my view with the table on it’s PARENT view gets popped from the nav stack, this CHILD I’m working on doesn’t seem to get any notice about it. Which is odd, because I’m definitely releaseing it.

I can call its -dealloc from my shell controller. I could call its -viewWillDisappear too, for that matter. Is that how I should be handling this? Probably I should put something into my shell controller’s viewWillDisappear like:

[[self.mainView subviews] makeObjectsPerformSelector:@selector(viewWillDisappear)];

…so that message propagates down to my child views.

Am I on the right track here, you think??

(Oh man… and that also explains why actions from inside this child table view can’t get to self.navigationController! I’ve been puzzled about that for weeks!)

  • 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-05-15T12:10:38+00:00Added an answer on May 15, 2026 at 12:10 pm

    Bugs like this, where a method gets called on an object after it’s been deallocated, often happen when a method gets called on a delegate after that delegate has been deallocated. The recommended practice to avoid bugs like these is to set any delegate (or delegate-like) properties of an object to nil before you release that object in the delegate’s dealloc method. I know that’s a confusing sentence, so I’ll explain it in the context of your bug.

    You have an asynchronous image download that finishes after you’ve backed out of your table view controller. When this happens, you’re calling reloadRowsAtIndexPaths:withRowAnimation:, which results in a call to tableView:numberOfRowsInSection: on the table view’s dataSource. This call is failing because that dataSource no longer exists.

    The problem is that the table view object still has your controller set as its dataSource and delegate properties, even after your controller has been deallocated. The solution is to simply set these properties to nil in your controller’s dealloc, like this:

    - (void)dealloc {
        self.tableView.dataSource = nil;
        self.tableView.delegate = nil;
        self.tableView = nil; // Releases as a side-effect due to @property (retain)
        [super dealloc];
    }
    

    Now when your table view tries to call tableView:numberOfRowsInSection: on its dataSource, it will send the message to the nil object, which swallows all messages silently in Objective C.

    You should also do the same thing with your ASIHTTPRequest’s delegate, by the way.

    Any time you have an asynchronous operation that calls delegate methods upon completion, it’s particularly important that you set that delegate to nil. When using UITableViewController under normal circumstances you can typically get away without setting the dataSource and delegate to nil, but in this case it was necessary because you’re calling methods on the tableView after its controller has gone away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Problem seemed to have been the Linux atheros driver for… May 16, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer Instead of this: deleteImage(ui.draggable); Delete the ui.helper, which is the… May 16, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer As per the syntax of TSQL - Like you require… May 16, 2026 at 2:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a view controller (view A) presenting a modal view (B) when the
I have a view controller: @interface DetailViewController : UIViewController It displays a map and
I have a view controller that is inside a popover, and I want to
Ok heres the situation. I have a View controller class that serves as the
I've got an app that initially loads in one view controller for a period
I currently have a UINavigationController based application that works just fine. I'd like to
I have a UIViewController that manages the display of some data. When the user
Situation: I have an Xcode project based on the Navigation-Based-Application template. So that means
I am breaking the normal paradigm of a UINavigationController, or at least I'm trying
I have a UITabBarController created programaticaly that manages 4 subclasses of UIViewController. Something like:

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.