1

Developing for MacOS, I have an NSMutableArray namesArray[] that contains 3 String objects. namesArray[] is represented in a tableView, where user can select multiple cells, each cell represents a single object. I am trying to initialize a second NSMutableArray savedNamesArray[], and add objects from the original namesArray[] based on the selected cells in my tableView using this method:

NSMutableArray *savedNamesArray = [[NSMutableArray alloc] initWithObjects:[namesArray objectsAtIndexes:[_tableView selectedRowIndexes]], nil];

The problem is, no matter how many objects I select, only one gets added to the new NSMutableArray. Any suggestions?

1
  • Please show the code on how you did connect the array with the table and how you catch the selection Commented Jun 19, 2019 at 20:43

1 Answer 1

3

You're adding one object, an array, to savedNamesArray. Use initWithArray: instead.

NSMutableArray *savedNamesArray = [[NSMutableArray alloc] initWithArray:[namesArray objectsAtIndexes:[_tableView selectedRowIndexes]]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.