我有一个表格,我想为每个被单击的单元格分配一个整数。如果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