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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:18:57+00:00 2026-06-07T21:18:57+00:00

I am new to xcode and making my first iPhone app. I have a

  • 0

I am new to xcode and making my first iPhone app.

I have a UITableview with 8 rows in a tabbed screen. I have a code which let’s the user select maximum 4 rows at a time and mark it with checks when selected.

Now, when I change the view and navigate to the next tab I want to save the text from these checked rows in a single NSString variable separated by commas.

Is it possible to do so? Thank you, any help is very much appreciated.

Here is the code of the first tab from where I want to save the selected rows.

@implementation Psychological

static int count = 0;
- (void)viewDidLoad {
[super viewDidLoad];

listOfItems = [[NSMutableArray alloc] init];

[listOfItems addObject:@"1 option"];
[listOfItems addObject:@"2 option"];
[listOfItems addObject:@"3 option"];
[listOfItems addObject:@"4 option"];
[listOfItems addObject:@"5 option"];
[listOfItems addObject:@"6 option"];
[listOfItems addObject:@"7 option"];
[listOfItems addObject:@"8 option"];    

}
#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
// Return the number of rows in the section.
return [listOfItems count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

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


// Configure the cell...
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.text = cellValue;



return cell;
}


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
    if(count < 4)
    {
    [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
    [selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];
        count++;
    }

} else {
    [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
    [selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];
    count --;
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];

}


- (void)dealloc {

[listOfItems release];
[super dealloc];
}


@end
  • 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-07T21:19:00+00:00Added an answer on June 7, 2026 at 9:19 pm

    the easiest way is make method wich will return string that you need. Method will look something like this:

    - (NSString *) selectedItems {
        NSMutableString *result = [NSMutableString string];
        for (int i = 0; i < [itemsArray count]; i++) {
            NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
            [tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
            if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
                [result appendFormat:@"%@",cell.textLabel.text];
            }
        }
        if (result.length > 2) {
            [result replaceCharactersInRange:NSMakeRange(result.length-1, 1) withString:@""];
        }
    return result;
    }
    

    To get this line in another view controller you should find Psychological view controller in navigationController.viewController and call this method.

    - (void) method {
        for (UIViewController *vc in self.navigationController.viewControllers) {
            if ([vc isKindOfClass:[Psychological class]]) {
                NSString *str = vc.selectedItems;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of building my first iPhone app (xCode,objective-c) which has
I JUST started a new XCode Project. The code I have added in so
I'm new to Objective C and XCode, currently working on my first iPhone Game.
I'm making my first app. I use Xcode 4 with storyboard to get a
I'm relatively new to XCode and I m working on photo collage App ,
I am completely new to Xcode and iOS developing in general. Basically I have
I'm new to xcode and the iphone sdk. I've been working with the view-based
I'm making a partial overlay modal in my app with the code from Semi-Modal
I am using regexkitlite to validate some data in my iPhone app in xcode.
I just upgraded to the latest 4.3 Xcode. I have my plist.which is preprocessed

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.