我有一个表格,我可以在UITableView
中选择多行。当我按“完成”时,我希望它将这些添加到三个不同的数组中。目前它只会保存第一个选定的行。如何保存UITableView
中的所有选定行?
这是我的“完成”按钮方法:
-(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];
}
答案 0 :(得分:1)
将初始化代码移至ViewDidLoad方法,如下所示
- (void)viewDidLoad
{
[super viewDidLoad];
[selectedName addObject:video.title];
[selectedAuthor addObject:video.author];
[selectedLink addObject:video.thumb];
return self;
}
并简单地添加如下所示的值
-(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];
}