【发布时间】:2014-01-02 09:23:32
【问题描述】:
我想知道是否有人可以提供任何启示,我有一个选定的球员名单。基本上,如果用户点击尚不存在的 indexRow,我想在点击时创建它。
我目前正在做这个检查;
if ([self.tableView cellForRowAtIndexPath:indexPath] == nil) {
这简直是崩溃了;
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
*** First throw call stack:
具体方法如下;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (indexPath.section == 2 && tableView == self.tableView) {
if (!self.usersSelectionArray || !self.usersSelectionArray.count || indexPath.row < [self.usersSelectionArray count]) {
// Create blank array and push to players
// Push to Players Screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
ListOfPlayersViewController *efvc = [storyboard instantiateViewControllerWithIdentifier:@"ListPlayers"];
[self.navigationController presentViewController:efvc animated:YES completion:nil];
} else {
if ([self.tableView cellForRowAtIndexPath:indexPath] == nil) {
// Push to Players Screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
ListOfPlayersViewController *efvc = [storyboard instantiateViewControllerWithIdentifier:@"ListPlayers"];
[self.navigationController presentViewController:efvc animated:YES completion:nil];
} else {
NSDictionary *cellDict = [self.usersSelectionArray objectAtIndex:indexPath.row];
// Save Names
[prefs setObject:[cellDict objectForKey:@"first_name"] forKey:@"teamFirstName"];
[prefs setObject:[cellDict objectForKey:@"last_name"] forKey:@"teamLastName"];
[prefs setObject:[cellDict objectForKey:@"avatar"] forKey:@"teamAvatar"];
// Push to Info Screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
PlayerInfoViewController *info = [storyboard instantiateViewControllerWithIdentifier:@"PlayerInfo"];
[self.navigationController presentViewController:info animated:YES completion:nil];
}
}
}
if (indexPath.section == 2 && tableView == self.awayTeamTableview) {
NSDictionary *cellDict = [self.awaySelectionArray objectAtIndex:indexPath.row];
// Save Names
[prefs setObject:[cellDict objectForKey:@"first_name"] forKey:@"awayFirstName"];
[prefs setObject:[cellDict objectForKey:@"last_name"] forKey:@"awayLastName"];
// Push to Players Screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
ManualPlayerViewController *manual = [storyboard instantiateViewControllerWithIdentifier:@"ManualPlayer"];
[self.navigationController presentViewController:manual animated:YES completion:nil];
}
int rowNumber = indexPath.row;
[prefs setInteger:rowNumber forKey:@"rowNumber"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
【问题讨论】:
-
您可以添加更多代码吗?你的选择代码和 cellforrowatindex 代码
-
你能更具体地说明你想要达到的目标吗?
-
是的,如果您可以显示更多数据源/委托方法的代码,我认为我们可以为您提供帮助
-
在编辑中添加方法 - 谢谢
-
如果用户点击不存在的 indexRow,则不会调用 didSelectRowAtIndexPath。
标签: ios objective-c arrays uitableview nsindexpath