如何在视图控制器之间传递nsarray



我正在制作一个应用程序,用户可以在uitableview中看到几个nsstring对象,当按下它们时,它会进入deatilview控制器。我正在尝试实现一个添加到收藏夹的功能,这样当用户按下uinavbaritem时,相应单元格的数据将传递到另一个视图控制器。

GrillTips *tips1 = [GrillTips new];
tips1.name = @"Tändvätska";
tips1.info = [NSArray arrayWithObjects:@"Tändvätska", nil];
GrillTips *tips2 = [GrillTips new];
tips2.name = @"Kol";
tips2.info = [NSArray arrayWithObjects:@"Kolen är det viktigste inom grillning", nil];

GrillTips *tips3 = [GrillTips new];
tips3.name = @"Få det Varmt!";
tips3.info = [NSArray arrayWithObjects:@"tjena", nil];

GrillTips *tips4 = [GrillTips new];
tips4.name = @"tjo";
tips4.info = [NSArray arrayWithObjects:@"what", nil];

GrillTips *tips5 = [GrillTips new];
tips5.name = @"tjo";
tips5.info = [NSArray arrayWithObjects:@"what", nil];

GrillTips *tips6 = [GrillTips new];
tips6.name = @"tjo";
tips6.info = [NSArray arrayWithObjects:@"what", nil];

GrillTips *tips7 = [GrillTips new];
tips7.name = @"tjo";
tips7.info = [NSArray arrayWithObjects:@"what", nil];

GrillTips *tips8 = [GrillTips new];
tips8.name = @"tjo";
tips8.info = [NSArray arrayWithObjects:@"what", nil];

GrillTips *tips9 = [GrillTips new];
tips9.name = @"tjo";
tips9.info = [NSArray arrayWithObjects:@"what", nil];


tips = [NSArray arrayWithObjects:tips1, tips2, tips3, tips4, tips5, tips6, tips7, tips8,    tips9, nil];
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"yourSegueIdentifier" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender //Pass your array here
{
    YourViewController *controller = (YourViewController*)segue.destinationViewController;
    controller.passedArray = theArrayYouWantToPass;//where passedArray is an array property inside of the viewController that you are segueing to
}

最新更新