ios 6在tableview中将整数分配给多个单元格
我有一个表格,我想为每个点击的单元格分配一个整数ios 6在tableview中将整数分配给多个单元格,ios,integer,tableview,cells,Ios,Integer,Tableview,Cells,我有一个表格,我想为每个点击的单元格分配一个整数 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; Information *detailViewController = [s
- (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}, etc}
然后,您只需要两行且无if语句:
detailViewController.infoInt= playersearch[indexPath.row][@"num"];
[detailViewController setTitle:playersearch[indexPath.row][@"player"]];
如果指定的整数等于单元格索引。你为什么不这样做呢:
[detailViewController setInfoInt:indexPath.row];
[detailViewController setTitle:[playersearch objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detailViewController animated:YES];
嘿,谢谢你的回复。我知道如何创建字典数组,但是({“player”:“John”,“num”:@0},{“player”:“Mark”,“num”:@1},{“player”:“Fred”,“num”:@3}的目的是什么,etc}?@AdrianFarfan,考虑到你的问题,我以为你想将这些特定的数字与这些特定的名称相关联。这不是你想要的吗?嘿,谢谢。这非常聪明。另外,假设我已经对该表视图进行了搜索。我有一个过滤项数组。过滤项时,单元格索引和信息int将更改。我想为筛选搜索中的每个项目分配一个名为extraInt的新整数。我应该如何处理此问题?