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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:08:42+00:00 2026-05-28T19:08:42+00:00

I have set up a UITableView with 3 sections that pulls from 3 NSArrays

  • 0

I have set up a UITableView with 3 sections that pulls from 3 NSArrays containing the keys for each section. I tried setting up a switch statement to manually set the detailTextLabels and accessory views for each cell, but every time I scroll the table view, the cells seemingly change on their own. Is there a more efficient way of doing this?

This is one method I tried using:

switch (indexPath.section) 
{
    // info
    case 0:{
        cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
        if ([cell.textLabel.text isEqualToString:@"Duration"]) 
        {
            cell.detailTextLabel.text = [task stringForDuration];
        }
        if ([cell.textLabel.text isEqualToString:@"Elapsed"]) 
        {
            // elapsed time
        }
        if ([cell.textLabel.text isEqualToString:@"Today"]) 
        {
            UISwitch *todaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
            [todaySwitch addTarget:self action:@selector(todaySwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
            [todaySwitch setOn:task.isToday];
            cell.accessoryView = todaySwitch;
            [todaySwitch release];
        }
    }
        break;
    // actions
    case 1:{
        cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
        if ([cell.textLabel.text isEqualToString:@"Priority"]) 
        {
            // priority
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
        if ([cell.textLabel.text isEqualToString:@"Finish Early"]) 
        {
            // finish early
        }
        if ([cell.textLabel.text isEqualToString:@"Set New Time"]) 
        {
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
        if ([cell.textLabel.text isEqualToString:@"Repeating"]) 
        {
            UISwitch *repeatingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
            [repeatingSwitch addTarget:self action:@selector(repeatingSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
            [repeatingSwitch setOn:task.isRepeating];
            cell.accessoryView = repeatingSwitch;
            [repeatingSwitch release];
            //cell.detailTextLabel.text = nil;
        }
    }
        break;
    // details
    case 2:{
        cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
        if ([cell.textLabel.text isEqualToString:@"Specifics"]) 
        {
            cell.detailTextLabel.text = task.specifics;
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
        if ([cell.textLabel.text isEqualToString:@"Repeated"]) 
        {
            // times repeated
        }
    }
        break;
    default:
        break;
}

And this is another:

// Info section
if ([indexPath section] == 0) 
{
    // duration
    cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
    if (indexPath.row == 0) 
    {
        cell.detailTextLabel.text = [task stringForDuration];
    }
    // elapsed time
    if (indexPath.row == 1) 
    {
        //cell.detailTextLabel.text = [task stringForTotalElapsedTime];
    }
    // today status
    if (indexPath.row == 2) 
    {
        UISwitch *todaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
        [todaySwitch addTarget:self action:@selector(todaySwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
        [todaySwitch setOn:task.isToday];
        cell.accessoryView = todaySwitch;
        [todaySwitch release];

    }
}
// actions section
if ([indexPath section] == 1) 
{
    cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
    // priority
    if (indexPath.row == 0) 
    {
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    // finish early
    if (indexPath.row == 1) 
    {
        //[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    // set new time
    if (indexPath.row == 2) 
    {
        //cell.accessoryView = repeatingSwitch;
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    // repeating
    if (indexPath.row == 3) 
    {
        UISwitch *repeatingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
        [repeatingSwitch addTarget:self action:@selector(repeatingSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
        [repeatingSwitch setOn:task.isRepeating];
        cell.accessoryView = repeatingSwitch;
        [repeatingSwitch release];
        cell.detailTextLabel.text = nil;
    }
}
// details section
if ([indexPath section] == 2) 
{
    cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
    // specifics
    if (indexPath.row == 0) 
    {
        //cell.detailTextLabel.text = taskDetails.specifics;
        cell.detailTextLabel.text = task.specifics;
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    // repeated
    if (indexPath.row == 1) 
    {
        [cell setAccessoryView:nil];
    }
}

Both of these attempts were inside cellForRowAtIndexPath

  • 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-28T19:08:43+00:00Added an answer on May 28, 2026 at 7:08 pm

    I ended up solving this question myself, thanks entirely to @Till’s comments. It seems the way UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier] works is by reusing already existing cells, so in order to use multiple cell types in a table, you have to use different reuse identifiers. Or, since I only have 7 or 8 table view cells, I just set the cell accessory view to nil for all cells that I want to not contain a UISwitch, like so:

    [cell setAccessoryType:UITableViewCellAccessoryNone];
    
    switch ([indexPath section]) 
    {
        case 0:
        {
            cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
            switch (indexPath.row) {
                case 0:
                {
                    cell.detailTextLabel.text = task.stringForDuration;
                    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                    cell.accessoryView = nil;
                }
                    break;
                case 1:
                {
                    cell.detailTextLabel.text = @"00:00";
                    [cell setAccessoryType:UITableViewCellAccessoryNone];
                    cell.accessoryView = nil;
                }
                    break;
                case 2:
                {
                    UISwitch *todaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
                    [todaySwitch addTarget:self action:@selector(todaySwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
                    [todaySwitch setOn:task.isToday];
                    cell.accessoryView = todaySwitch;
                    [todaySwitch release];
                    [cell setAccessoryType:UITableViewCellAccessoryNone];
                    cell.detailTextLabel.text = @"";
                }
                    break;
                default:
                    break;
            }
        }
            break;
        case 1:
        {
            cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
            switch (indexPath.row) {
                case 0:
                {
                    cell.detailTextLabel.text = @"Low";
                    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                    cell.accessoryView = nil;
                }
                    break;
                case 1:
                {
                    cell.detailTextLabel.text = @"";
                    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                    cell.accessoryView = nil;
                }
                    break;
                case 2:
                {
                    UISwitch *repeatingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
                    [repeatingSwitch addTarget:self action:@selector(repeatingSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
                    [repeatingSwitch setOn:task.isRepeating];
                    cell.accessoryView = repeatingSwitch;
                    [repeatingSwitch release];
                    cell.detailTextLabel.text = @"";
                    [cell setAccessoryType:UITableViewCellAccessoryNone];
                }
                    break;
                default:
                    break;
            }
        }
            break;
        case 2:
        {
            cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
            switch (indexPath.row) {
                case 0:
                {
                    cell.detailTextLabel.text = task.specifics;
                    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                    cell.accessoryView = nil;
                }
                    break;
                case 1:
                {
                    cell.detailTextLabel.text = @"0";
                    [cell setAccessoryType:UITableViewCellAccessoryNone];
                    cell.accessoryView = nil;
                }
                    break;
                default:
                    break;
            }
            break;
        }
        default:
            break;
    }
    

    This way saved me the trouble of dealing with multiple reuse identifiers.

    • 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 I have set-up with 2 sections. The code below
I have a UITableView. I'm population it from a NSDictionary with arrays for each
I have an UITableView, and in it I have different sections - words that
So I have my UITableView, with 2 sections and 1 cell in each, and
I have set up a UITableView which has 3 sections in, with 3 rows
I have a UITableView With Two Sections. First section has one row and the
I have set up a UITableView-based app, which has a .plist for holding the
I have an UITableView set up with a NSArray with 10 indexes. Right now,
I have set up a Django application that uses images. I think I have
In my iPhone app I have a UIViewController that has a UITableView and another

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.