我有一個表格,我想爲每個被單擊的單元格分配一個整數。如果ios 6將整數分配給tableview中的多個單元格
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Information *detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"Information1"];
此檢查細胞文本等於「PLAYER1」並給它分配的整數,並將該標題至下一個視圖控制器。
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"John"]){
detailViewController.infoInt=0;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"Mark"]){
detailViewController.infoInt=1;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"Fred"]){
detailViewController.infoInt=2;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"Matt"]){
detailViewController.infoInt=3;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
if([[filteredSearch objectAtIndex:indexPath.row]isEqual:@"Javier"]){
detailViewController.infoInt=3;
[detailViewController setTitle:@"player 4"];
}
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"Andreas"]){
detailViewController.infoInt=4;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
if([[playersearch objectAtIndex:indexPath.row]isEqual:@"Lionel"]){
detailViewController.infoInt=5;
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
}
[self.navigationController pushViewController:detailViewController animated:YES];
對於我的應用程序這個擁有約200次工作要做,我想知道是否有在這我可以簡化我的代碼的方式。順便說一句,我有一個財產清單,其中包含所有玩家的名字。
嘿謝謝你的答覆。我知道如何創建一個字典數組,但是({@「player」:@「John」,@「num」:@ 0},{@「player」:@「Mark」,@「num」 :@ 1},{@「player」:@「Fred」,@「num」:@ 3}等等} –
@AdrianFarfan,考慮到你的問題,我想你想把這些特定的數字與那些特定的名字聯繫起來。這是不是你想要的? – rdelmar