I'm creating a new app, and in the app i want two tableviews. One for showing a list, and another one to show the stuff the users picks from the list. So far i've created the arrays to contain the items, and i've gotten the views to pass between each other. I cannot seem to get the selected items shown in the other tableview.
Here's some code from the list-tableview (the data gets passed when 'Done' is pushed). viewC is an instance of the other view, used to get acces to it.
-(IBAction)dismissValgScene {
for (int i = 0; i < ValgteMedierarray.count; i++) {
NSLog(@"%@", [ValgteMedierarray objectAtIndex:i]);
}
viewC.TilvalgteMedierArray = [NSMutableArray arrayWithArray:ValgteMedierarray];
NSLog(@"1: antal i tilvalgteArray = %lu", (unsigned long)viewC.TilvalgteMedierArray.count);
[viewC.tableView reloadData];
NSLog(@"2: antal i tilvalgteArray = %lu", (unsigned long)viewC.TilvalgteMedierArray.count);
[self dismissViewControllerAnimated:YES completion:nil];
}
This is the method for the Done button, which adds the selected items to an array in the other view. (that is the viewC.TilvalgteMedierArray)
Here is some code from the other view, which should show the selected items
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [TilvalgteMedierArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
// Configure the cell...
cell.textLabel.text = [TilvalgteMedierArray objectAtIndex:indexPath.row];
return cell;
}
Hope you guys can help, and please just ask me to elaborate whatever you don't understand of my coding :)
(I apoligize if this has been answered elsewhere, but i have been looking for hours without finding a solution).
EDIT:
A thank you to all who has been trying to help me. :)
I have now found a solution by using the Unwind Segue method. Anyone with a similar problem can look at these links:
How to make an unwind segue: What are Unwind segues for and how do you use them?
How to pass data with the unwind segue: iOS 6 - can i return data when i unwind a segue?