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 5962271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:04:56+00:00 2026-05-22T19:04:56+00:00

I have navigation application with 3 levels of hierarchy. My first level is tabel

  • 0

I have navigation application with 3 levels of hierarchy. My first level is tabel view controller. The nib file of this controller is “TableView”. I have problem here. My code is this:

RootViewController

#import "RootViewController.h"
#import "SubCategory.h"
#import "OffersViewController.h"

@implementation RootViewController

@synthesize subCategories;
@synthesize offersView;

- (void)dealloc
{
    NSLog(@"root dealloc");
    //[subCategories release];
    [super dealloc];
}

- (void)viewDidLoad
{
    NSLog(@"root view load");
    [super viewDidLoad];
    self.title  = @"Sub Categories";

    NSString *jsonArray = [NSString stringWithFormat:@"{ "
                       @" \"sub-categories\": { "
                       @" \"parent\": \"1\", "
                       @" \"count\": \"2\", "
                       @" \"sub-category\": [{ "
                       @" \"id\": \"1\", "
                       @" \"name\": \"Buy\" "
                       @" }, "
                       @" { "
                       @" \"id\": \"2\", "
                       @" \"name\": \"Sell\" "
                       @" }] "
                       @" } "
                       @" }"];

    SubCategory* categories = [[SubCategory alloc] init];
    subCategories = categories;
    [subCategories parseJSON:jsonArray];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    NSLog(@"root sections");
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    NSLog(@"root numberOfRows");
return [subCategories.subCategoryName count];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"root didSelectRow");
    OffersViewController * offers = [[OffersViewController alloc]    initWithNibName:@"OffersView" bundle:nil];

    offersView = offers;
    // I have exception on this row. exception is:
    //-[__NSArrayI objectAtIndex:]: message sent to deallocated instance 0x4b04c00
    offersView.title = [NSString stringWithFormat:@"%@", [subCategories.subCategoryName objectAtIndex:indexPath.row]];

    [self.navigationController pushViewController:offersView animated:YES];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"root cellForRow");
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cachedCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] init] autorelease];
    }

    cell.textLabel.text = [subCategories.subCategoryName objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

@end

SubCategory

#import "SubCategory.h"
#import "JSON.h"

@implementation SubCategory

@synthesize parentId;
@synthesize count;
@synthesize subCategoryId;
@synthesize subCategoryName;


- (void) parseJSON: (NSString*) jsonArray {
     NSDictionary *results = [jsonArray JSONValue];

    NSString *parent = (NSString*) [[results objectForKey:@"sub-categories"] objectForKey:@"parent"];
    parentId = [parent intValue];

    NSString *cnt = (NSString*) [[results objectForKey:@"sub-categories"] objectForKey:@"count"];
    self.count = [cnt intValue];

    NSDictionary *subCategories = [[results objectForKey:@"sub-categories"] objectForKey:@"sub-category"];


    NSMutableArray *namesArray = [[NSMutableArray alloc] initWithCapacity:[subCategories count]];
    NSMutableArray* idArray = [[NSMutableArray alloc] initWithCapacity:[subCategories count]];

    for (NSDictionary *subCategory in subCategories) {        
        [idArray addObject:[subCategory objectForKey:@"id"]];
        [namesArray addObject:[subCategory objectForKey:@"name"]];
    }

    subCategoryId = [NSArray arrayWithArray:idArray];
    subCategoryName = [NSArray arrayWithArray:namesArray];

    [idArray release];
    [namesArray release];
//[parent release];
//[cnt release];
}

@end

I don’t know why my object is released. Can someone help me.

EDIT: Added SubCategory code

  • 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-22T19:04:57+00:00Added an answer on May 22, 2026 at 7:04 pm

    Here’s the problem:

    NSMutableArray *namesArray = [[NSMutableArray alloc] initWithCapacity:[subCategories count]];
    NSMutableArray* idArray = [[NSMutableArray alloc] initWithCapacity:[subCategories count]];
    
    ...
    
    subCategoryId = [NSArray arrayWithArray:idArray];
    subCategoryName = [NSArray arrayWithArray:namesArray];
    
    [idArray release];
    [namesArray release];
    

    At this point, subCategoryId and subCategoryName are autoreleased. This means they won’t be accessible after the parseJSON: method finishes. You have two options:

    // Because idArray and namesArray are already retained (you alloc'd them)
    subCategoryId = idArray;
    subCategoryName = namesArray;
    

    or:

    ...
    // this is equivalent to what you have now, except these two will be retained.
    // this is different from the above because subCategoryId and subCategoryName are now NSArrays, whereas above they were NSMutableArrays.
    subCategoryId = [idArray copy];
    subCategoryName = [namesArray copy];
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have tested a navigation controller at the root level. - (void)applicationDidFinishLaunching:(UIApplication *)application
I have a Navigation application that has a view controller in it.. I am
I have a Navigation Controller with two Views. The First View is a ViewController
I have a tab-bar and navigation controller application (like Youtube app or Contacts app).
I have a UITabBar in the detail view of my navigation based application. I
I have a tab bar along with navigation controller iphone application. Now I need
I have a core data application which uses a navigation controller to drill down
I have a navigation based application using Core Data and several levels of drill-down
I have an application that has a top level navigation menu which consists of
I have a navigation based application which also needs to have a view always

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.