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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:40:27+00:00 2026-05-31T23:40:27+00:00

I have a categories table view controller. In my app, categories can have subcategories.

  • 0

I have a categories table view controller. In my app, categories can have subcategories.

For instance, clothes can have 3, but maybe books can have no one and go directly to articles.

How can I do to only implement one categories table view controller, and reload with new values if category cell clicked has subcategories?

This is what I have but it wasn’t successful:

- (void) loadCategories{

    NSString *urlStr;

    if (self.subCategoria){

       urlStr =  [NSString stringWithFormat:@"http://webservic.es/articulos.php?idc=%@&store=0", self.subCategoria];
    }else{

       urlStr = @"http://webservices.es/articulos.php";

    }

    NSLog(@"URL:%@", urlStr);


    NSURL *url = [NSURL URLWithString:urlStr];

    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10.0];

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

         categoria *categoria = [self.categoriasArray objectAtIndex:self.tableView.indexPathForSelectedRow.row];

         if (categoria.subcategoria){
             self.subCategoria = categoria.subcategoria;
             [self viewDidAppear:YES];
             [self.tableView reloadData];
         }else{
             ArticulosController *articulosController =segue.destinationViewController;
             articulosController.id_categoria = categoria.id_categoria;

         }
  }

Thanks

  • 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-31T23:40:29+00:00Added an answer on May 31, 2026 at 11:40 pm

    There are two ways to consider your question. Do you want to have a single TableViewController class (and possibly multiple instances of it), or a singleton instance of that class?

    I’d say the latter is more trouble than it’s worth. The kit isn’t designed to work this way, so all of the shortcuts it provides you become work you’ll have to do yourself — and the best you get from this is a modest improvement in memory usage. (More likely you’ll have bugs introduced because it’s easy to miss something when reconfiguring the same instance to represent different data.)

    On the other hand, reusing a single view controller class is something the kit is designed to help you with, and since it sounds like you’re using storyboards already, you’re halfway there. In your prepareForSegue:sender: implementation, you’ll always have a destinationViewController — so all you need to do is configure it to represent the subcategory (by setting its subcategory property, it looks like).

    (In fact, if you’re using storyboard segues, you’re getting new instances of your class created for you whether you like it or not… if you really want to go for the singleton approach, you’ll have to abandon the segue, which means you’ll lose the built-in navigation stack behavior.)

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

Sidebar

Related Questions

I have a Categories table in which each category has a ParentId that can
I have a categories table, which one of the fields serves as the foreign
I have a table of categories. Each category can either be a root level
Greetings, fellow coders! I have this table that contains categories and subcategories (actually I
I have a table view with a list of categories and each category (understand
I'm recoding a splitview controller app I did so the table view isn't always
I have basically the following table, Categories id name categories_id_categories 1 Clothes null 2
I have a MySQL table set up using phpMyAdmin which you can view in
My app has a set of categories. A category can have sub-categories. DirectoryCategoryController is
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.

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.