2014-01-09 21 views
0

我有一個表格,我可以在UITableView中選擇多行。當我按下「完成」時,我希望它將這些添加到三個不同的數組中。目前它只會保存第一個選中的行。我怎樣才能讓它保存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]; 
} 

回答

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]; 

}

相關問題