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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:39:32+00:00 2026-05-14T23:39:32+00:00

I have a UITableView with 3 sections that are hard coded. Everything is working

  • 0

I have a UITableView with 3 sections that are hard coded. Everything is working fine, but I am not sure if I am doing it correctly.

Define number of rows in section:

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

        //Bio Section
        if(section == 0){
            rows = 2;
        }
        //Profile section
        else if(section == 1){
            rows = 5;
        }
        //Count section
        else if(section == 2){
            rows = 3;
        }
    }  

    return rows;
}

Here is where I build my cells:

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tblView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.numberOfLines = 5;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:(10.0)];
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;

    if ([self.message_source isEqualToString:@"default"]) {
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                cell.textLabel.text = [Utils formatMessage:[NSString stringWithFormat: @"%@", mySTUser.bio]];
                cell.detailTextLabel.text = nil;
            }
            else if(indexPath.row == 1){
                cell.textLabel.text = [NSString stringWithFormat: @"%@", mySTUser.website];
                cell.detailTextLabel.text = nil;
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
        }
} //more code exists, but you get the point...

Now I define my number of sections

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tblView 
{ 
     return 3;
}

Is this the proper way of hard-coding my UITableView? Will I run into any issues when cells are reused?

  • 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-14T23:39:32+00:00Added an answer on May 14, 2026 at 11:39 pm

    You might consider using a switch-case tree with an enumerated type, to replace the if conditionals that test for various hard-coded integers. This blog post explains this option in more detail. Using switch-case with your table view delegate methods will make your code much more readable and flexible. Otherwise, your reuse code looks correct.

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

Sidebar

Related Questions

I have a UITableView that was working fine until I added sections to it
I have a UITableView that has five sections. Just as the title describes cellForRowAtIndexPath
I have a grouped UITableView where not all sections may be displayed at once,
I have set up a UITableView with 3 sections that pulls from 3 NSArrays
I have a UITableView that is grouped into sections and has a number of
I have a UITableView that I have set-up with 2 sections. The code below
I have an UITableView, and in it I have different sections - words that
I have a UITableView that implements UISearchBarDelegate. I have two sections in my self.searchDisplayController.searchResultsTableView
I have a UITableView that contain 3 sections, It is possible in the edit
I have a UITableView that has 3 sections. My individual cells vary in height

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.