我有一个表格,我想在其中为每个单击的单元格分配一个整数。
- (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 次,我想知道是否有一种方法可以简化我的代码。顺便说一句,我有一个包含所有玩家姓名的财产清单。