我有一個包含對象的數組,這些對象顯示在TableViewController
中,每行都有一些字段,如team id
,name
和points
。如何根據值在prepareforSegue中顯示數組中的條目?
現在,我創建了一個additional team info
陣列多個對象/屬性 - 完整的團隊名,預科和團隊ID再等
我想的是,當用戶點擊一排我TableViewController
它讀取團隊ID,並在prepareforSegue
有一些方法來搜索我的additional team info
數組,並找到匹配的團隊ID,並顯示在另一個segue對象數據。下面是我的一些代碼:
NSMutableArray *allInfo = [[NSMutableArray alloc]init];
for(int i = 0; i < 14; i++) {
ExtraTeamInfoObject *temp = [[ExtraTeamInfoObject alloc] init];
temp.teamFullNames = _teamFullNames[i];
temp.teamId = _teamId[i];
temp.teamStadiumNames = _teamStadiumNames[i];
temp.stadiumCapacity = _stadiumCapacity[i];
temp.clubFoundationDate = _clubFoundationDate[i];
temp.stadiumBuiltYear = _stadiumBuiltYear[i];
temp.teamCity = _teamCity[i];
temp.clubPresident = _clubPresident[i];
temp.headCoach = _headCoach[i];
temp.championshipsWon = _championshipsWon[i];
temp.domesticCupsWon = _domesticCupsWon[i];
temp.domesticLeagueCupsWon = _domesticLeagueCupsWon[i];
temp.domesticSuperCupsWon = _domesticSuperCupsWon[i];
temp.championsleaguesWon = _championshipsWon[i];
temp.europaleaguesWon = _europaleaguesWon[i];
temp.europeanSuperCupsWon = _europeanSuperCupsWon[i];
temp.worldclubchampionshipsWon = _worldclubchampionshipsWon[i];
[allInfo addObject:temp];
}
for (int i = 0; i < 14; i++) {
NSLog(@"Show me the goods %@", [allInfo[i] teamFullNames]); // just making sure the objects are being created correctly.
}
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"teamDetailsSeg"]){
TeamDetailsTableViewController *detailViewController = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
long row = [myIndexPath row];
//detailViewController.teamDetailModel = before I would just type the array here like _teamFullName[row] and it would give me data i needed
}
}
爲了篩選的目的,你可以使用字典而不是數組結構:@(team_id)=> ExtraTeamInfoObject – vokilam