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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:50+00:00 2026-05-28T03:13:50+00:00

Our app has changed every month. It is very hard to modify sections and

  • 0

Our app has changed every month. It is very hard to modify sections and rows (add, remove). I need to scan every UITableViewDelegate’s method and changed it. I’m using switch-case approach. I’m need more elegant approach.

I posted my code for two methods but in reality I have to modify 5 methods.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 NSInteger rows;

 switch (section) 
 {
    case 0:
    {
        rows = 3;
        break;
    }            
    case 1:
    {
        rows = 4;
        break;
    }
    case 2:
    {
        rows = 4;
        break;
    }
    case 3:
    {
        rows = 4;
        break;
    }
    case 4:
    {
        rows = 7;
        break;
    }

    default:
        rows = 1;
        break;
 }

 return rows;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 switch (indexPath.section) 
 {
    case 0:
    {
        switch (indexPath.section) 
        {
            case 0:
            {
                break;
            }
            case 1:
            {
                break;
            }
            case 2:
            {
                break;
            }                    
            default:
                break;
        }

        break;            
     }
  }
}
  • 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-28T03:13:51+00:00Added an answer on May 28, 2026 at 3:13 am

    Create a class say TableManager

    Pass your table view to this class and let this class provide the data for all your tableviews. Differentiate between the tableviews by settings tag values to them.

    So now you will have control of all your tableviews in this one class.

    Instead of the numbers in the switch case use enum. It will increase readability in your code.

    Depending upon your actual requirement you can manipulate this class’s behavior from a plist perhaps.

    Let me provide some code:

    Define an enumerator

    typedef enum { FIRST_TABLE, SECOND_TABLE, THIRD_TABLE } TableViews;
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    
    [TableManager getNumberOfRowsForTableView:tableView];
    
    }
    

    In your TableManager

    + (NSInteger)getNumberOfRowsForTableView:(UITableView*)theTableView
    {
    
    if(theTableView.tag == FIRST_TABLE) //FIRST_TABLE is an enum
    {
     //Your conditions goes here
     return 3;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After update our iphone app can not access the keychain. The distribution certificate has
Our app uses a component that requires a license file in the directory with
Our app runs in jvm 32 bit, even when in windows x64. Now, at
Our app servers (weblogic) all use log4j to log to the same file on
Our app uses a string to house character-values used to indicate enum values. for
Our app supports different browser version from IE to Firefox to Chrome. Now, some
Our app, distributed via ClickOnce, takes 10.8 seconds on average to start up. After
Our app is a simple portal (will be deployed as azure webrole) with following
In our app under development we are using Core Data with a sqlite backing
We are rewriting our app to make it Windows Vista/7 compliant. In order to

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.