大佬教程收集整理的这篇文章主要介绍了objective-c – “objectAtIndex”的NSUserDefaults错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Team *team = [leagueLocal.teams objectATindex:indexpath.row];
错误是“使用未声明的标识符’indexpath’”…但我不确定我会在objectATindex上放什么:除了indexpath.row,因为这对我来说在这个应用程序的TableView部分中有用.
大图,我正在尝试使用NSUserDefaults保存所选的团队名称.团队名称通过JSON从Web服务中提取.
这是我到目前为止NSUserDefaults部分的完整代码:
// Create User Defaults Variable NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // Tell it where to look Sport *sportLocal = [sports objectATindex:0]; League *leagueLocal = [sportLocal.leagues objectATindex:0]; Team *team = [leagueLocal.teams objectATindex:indexpath.row]; // This is where error is // Store the data,this is the stuff I want to save [defaults setObject:team.abbreviation forKey:[NSString StringWithFormat:@"teamAbbreviation%d",_buttonnumber]]; // After saving,synchronize data [defaults synchronize];
谢谢您的帮助!如果需要更多信息,或者我可以帮助澄清是否需要,请告诉我.
编辑 – 我在错误下方的viewDidLoad中添加了一个NSLog,看看我得到了什么,然后它返回null:NSLog(@“index at index:%@”,team.abbreviation);
你有几个选项来获取你想要的indexPath:
Team *team = [leagueLocal.teams objectATindex:[NSIndexPath indexPathForRow:i inSection:k]; //where i and k are Integers that inDicate the row/section for the tableViewCell your looking for...(k would just be equal to 0 if you only have one section)
或者另一种方式是,如果用户之前已经选择了您要查找的@L_489_18@,那么您可以使用:
NSIndexPath *indexPath=[self.tableView indexPathForSELEctedRow]; Team *team = [leagueLocal.teams objectATindex:indexPath.row];//Now you can use it the way you have it written in your question
希望能帮助到你!
以上是大佬教程为你收集整理的objective-c – “objectAtIndex”的NSUserDefaults错误全部内容,希望文章能够帮你解决objective-c – “objectAtIndex”的NSUserDefaults错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。