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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:06:00+00:00 2026-06-14T19:06:00+00:00

In my app, the user changes the fields that appear in a tableView depending

  • 0

In my app, the user changes the fields that appear in a tableView depending on the cells selected by him/her. (FYI… I have permitted multiple cell selection.) Just when the user presses the back button, the program copies the textLabel of the selected cells to the placeholder of the parent viewController.

Here’s the relevant section of my code:

- (void)willMoveToParentViewController:(UIViewController *)parent
{
int tempCount = 0;

for (int section = 0; section < 3; section++)
{
    int rowMax;

    if (section == 0)
        rowMax = 3;

    else if (section == 1)
        rowMax = 5;

    else if(section == 2)
        rowMax = 3;

    for(int row = 0; row < rowMax; row++)
    {
        NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:row inSection:section];

        UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:tempIndexPath];

        if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
        {
            NSLog(@"tempCount = %d", tempCount);
            tempCount++;

            if (tempCount == 1)
                chosenFieldsViewController.field0.placeholder = selectedCell.textLabel.text;

            else if(tempCount == 2)
                chosenFieldsViewController.field1.placeholder = selectedCell.textLabel.text;

            else if(tempCount == 3)
                chosenFieldsViewController.field2.placeholder = selectedCell.textLabel.text;

        }
    }
}
}

I realized that after selecting the cells if the tableView is scrolled down, the selected cells do not appear as placeHolder on the parentVC. From my analysis I think that once I scroll down, the cells are deleted from the memory. So despite the fact that the cells are selected, they fail to show up on the parent VC.

If so, why do I see the cells appear selected when I scroll up?

I would be grateful if somebody can suggest how I can keep a track of the selected cells even when the user scrolls.

Thanks.

Edit 1

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

if(selectedCell.accessoryType != UITableViewCellAccessoryCheckmark && count<3)
{
    selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
    count ++;
}

else if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
    selectedCell.accessoryType = UITableViewCellAccessoryNone;
    count--;
}

}

Edit 2

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

NSString *CellIdentifier = [NSString stringWithFormat:@"CellForRow%dSection%d",indexPath.row, indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

cell.selectionStyle = UITableViewCellSelectionStyleNone; // VERY IMPORTANT

if (indexPath.section == 0)
{        
    switch(indexPath.row)
    {
        case 0:
            cell.textLabel.text = @"Class A";
            break;

        case 1:
            cell.textLabel.text = @"Class B";
            break;

        case 2:
            cell.textLabel.text = @"Class C";
            break;

        default:
            break;
    }
}

if(indexPath.section == 1)
{        
    switch(indexPath.row)
    {
        case 0:
            cell.textLabel.text = @"Class D";
            break;

        case 1:
            cell.textLabel.text = @"Class E";
            break;

        case 2:
            cell.textLabel.text = @"Class F";
            break;

        case 3:
            cell.textLabel.text = @"Class G";
            break;

        case 4:
            cell.textLabel.text = @"Class H";
            break;

        default:
            break;
    }
}

if(indexPath.section == 2)
{
    switch (indexPath.row)
    {
        case 0:
            cell.textLabel.text = @"Class I";
            break;

        case 1:
            cell.textLabel.text = @"Class J";
            break;

        case 2:
            cell.textLabel.text = @"Class K";
            break;

        default:
            break;
    }
}

return cell;
}
  • 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-06-14T19:06:02+00:00Added an answer on June 14, 2026 at 7:06 pm

    Declare a dictionary as,

    @property (nonatomic, retain) NSMutableDictionary *selectedTextListDict;
    

    In viewDidLoad,

    NSMutableDictionary *selectedTextListDict = [[NSMutableDictionary alloc] init];
    

    Then change these methods as,

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    
        if(selectedCell.accessoryType != UITableViewCellAccessoryCheckmark && count < 3)
        {
            NSString *rowKeyString = [NSString stringWithFormat:@"%d", indexPath.row];
            NSString *sectionKeyString = [NSString stringWithFormat:@"%d", indexPath.section];
    
            NSMutableDictionary *row = [self.selectedTextListDict valueForKey:sectionKeyString];
            if (!row) {
                row = [[NSMutableDictionary alloc] init];
            }
            [row setObject:selectedCell.textLabel.text forKey:rowKeyString];
            [self.selectedTextListDict setObject:row forKey:sectionKeyString];
    
            selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
            count ++;
        }
    
        else if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
        {
    
            NSString *rowKeyString = [NSString stringWithFormat:@"%d", indexPath.row];
            NSString *sectionKeyString = [NSString stringWithFormat:@"%d", indexPath.section];
    
            NSMutableDictionary *row = [self.selectedTextListDict valueForKey:sectionKeyString];
            [row removeObjectForKey:rowKeyString];
    
            if ([[row allKeys] count] == 0) {
                [self.selectedTextListDict removeObjectForKey:sectionKeyString];
            } else {
                [self.selectedTextListDict setObject:row forKey:sectionKeyString];
            }
    
            selectedCell.accessoryType = UITableViewCellAccessoryNone;
            count--;
        }
    }
    
    
    - (void)willMoveToParentViewController:(UIViewController *)parent
    {
        NSArray *selectedTextSectionKeysList = [self.selectedTextListDict allKeys];
        NSArray *sortedSelectedTextSectionKeysList = [selectedTextSectionKeysList sortedArrayUsingSelector:@selector(intValue)];
        int tempCount = 0;
    
        for (NSString *sectionString in sortedSelectedTextSectionKeysList) {
    
            NSMutableDictionary *rowDict = [self.selectedTextListDict valueForKey:sectionString];
    
            if (rowDict) {
    
                NSArray *selectedTextRowKeysList = [rowDict allKeys];
                NSArray *sortedSelectedTextRowKeysList = [selectedTextRowKeysList sortedArrayUsingSelector:@selector(intValue)];
    
                for (NSString *rowString in sortedSelectedTextRowKeysList) {
    
                    tempCount++;
    
                    if (tempCount == 1)
                        chosenFieldsViewController.field0.placeholder = [rowDict valueForKey:rowString];
    
                    else if(tempCount == 2)
                        chosenFieldsViewController.field1.placeholder = [rowDict valueForKey:rowString];
    
                    else if(tempCount == 3)
                        chosenFieldsViewController.field2.placeholder = [rowDict valueForKey:rowString];
                }
    
            }
        }
    }
    

    Edit 1:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if([segue.identifier isEqualToString:@"GoToModifyFieldsViewController"])
        {
            ModifyFieldsViewController *modifyFieldsViewController = segue.destinationViewController;
            modifyFieldsViewController.chosenFieldsViewController = self;
    
            field0.placeholder = @"";
            field1.placeholder = @"";
            field2.placeholder = @"";
    
            if(self.selectedTextListDict)
                self.selectedTextListDict = [[NSMutableDictionary alloc] init];
        }
    }
    

    Declare a dictionary in ChosenFieldsViewController: as,

    @property (nonatomic, retain) NSMutableDictionary *selectedTextListDict;
    

    In viewDidLoad,

    selectedTextListDict = [[NSMutableDictionary alloc] init];
    

    Therefore, rather using self.selectedTextListDict, use: chosenFieldsViewController.selectedTextListDict in ModifyFieldsViewController.

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

Sidebar

Related Questions

I have an app that allows the user to change the text size. On
I have a simple VB.NET 2008 app that helps users to edit fields in
My app changes statuses in iChat according to the user's hot keys, using AppleScript.
In my app,user can select image from gallery and after that he can zoom
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
In my app, I have a User model, which includes a number of attributes
I have an app that potentially tracks a large amount of data during app
I'm building an iPhone app that, among other things, allows the user to take
In my app I have an advanced search page which uses a tableview with
I have an asp.net web app that's going through a pen test by internal

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.