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

时间:2013-07-01 19:17:02

标签: ios uitableview nsarray

我正在创建一个应用程序,用户在uitableview中看到几个nsstring对象,当它们被按下时,它会进入deatilviewcontroller。我正在尝试实现添加到收藏夹功能,因此当用户按下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];

1 个答案:

答案 0 :(得分:3)

-(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
}