user3140296
user3140296

Reputation: 169

Save multiple selected rows in UITableView

I have a table where I can select multiple rows in the UITableView. When I press “Done” I want it to add these into three different arrays. At the moment it will only save the first selected row. How can I make it save all selected rows in the UITableView?

Here is my “Done” button method:

-(IBAction)songsDone:(id)sender{

    selectedName = [[NSMutableArray alloc] init];
    [selectedName addObject:video.title];

    selectedAuthor = [[NSMutableArray alloc] init];
    [selectedAuthor addObject:video.author];

    selectedLink = [[NSMutableArray alloc] init];
    [selectedLink addObject:video.thumb];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    SongsViewController *songsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SongsViewController"];
    [self.navigationController pushViewController:songsViewController animated:YES];
}

Upvotes: 0

Views: 115

Answers (1)

vignesh kumar
vignesh kumar

Reputation: 2330

Move the initializing code to ViewDidLoad method like below

- (void)viewDidLoad
{
    [super viewDidLoad];
    [selectedName addObject:video.title];
    [selectedAuthor addObject:video.author];
    [selectedLink addObject:video.thumb];
    return self;
}

and simply add values like below

-(IBAction)songsDone:(id)sender{


[selectedName addObject:video.title];


[selectedAuthor addObject:video.author];


[selectedLink addObject:video.thumb];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
SongsViewController *songsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SongsViewController"];
[self.navigationController pushViewController:songsViewController animated:YES];

}

Upvotes: 1

Related Questions