0
votes

First of all excuse me for my english. I'm new at programming and im trying to do the next:

I have a tableView with ingredients, so when i click in any of them i want to add them to a new array of available ingredients.

Ive been looking and i think the void should be

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}

What should i do next?

My idea is to have a tab of Ingredients and when i tap one, add it to another tab called "My refrigerator" and when it tap one, delete it from the tableview

Thank you very much!

2

2 Answers

1
votes

Create a new mutable array of clicked ingredients:

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

    [newIngredientsArray addObject: [tableViewArray objectAtIndex: indexPath.row]];

}

Then you can pass this array to your detail view controller.

0
votes

Yes, you will use -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath that will get called when the user clicks the cell. Then you can find which cell was selected from indexPath.row will tell you the number of the row.

As far as what to do next it will depend on the rest of your application. You will probably have an array of objects you populated your table from, so you will use the indexPath.row to get it from that array and add it your your MyRefrigerator array.