This question already has an answer here:
这个问题在这里已有答案:
- Convert NSInteger to NSIndexpath 4 answers
- 将NSInteger转换为NSIndexpath 4个答案
I am making a basic quiz application.The choices are in the form of a table view. If the user moves to a previous question, I want to show him his previously selected choice. I have stored the choice in NSUserDefaults. How do I convert this int value to NSIndexpath and use it in my tableview?
我正在做一个基本的测验应用程序。选择是以表格视图的形式。如果用户移动到上一个问题,我想向他显示他之前选择的选项。我已将选择存储在NSUserDefaults中。如何将此int值转换为NSIndexpath并在我的tableview中使用它?
3 个解决方案
#1
54
See the NSINdexPath UIKit Additions
请参阅NSINdexPath UIKit Additions
In your case you can use (Swift):
在你的情况下你可以使用(Swift):
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
Swift 3.0:
Swift 3.0:
let indexPath = IndexPath(row: 0, section: 0)
#2
4
Duplicate of This post
这篇文章重复一遍
I copied the recieved answer here
我在这里复制了收到的答案
For an int index:
对于int索引:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
Creates Index of the item in node 0 to point to as per the reference.
创建节点0中项目的索引以指向根据引用。
To use the indexPath in a UITableView, the more appropriate method is
要在UITableView中使用indexPath,更合适的方法是
NSIndexPath *path = [NSIndexPath indexPathForRow:yourInt inSection:section];
#3
0
You can get indexpath using below code
您可以使用下面的代码获取indexpath
NSIndexPath *index = [NSIndexPath indexPathForRow:YOURINTSTORED inSection:0];
#1
54
See the NSINdexPath UIKit Additions
请参阅NSINdexPath UIKit Additions
In your case you can use (Swift):
在你的情况下你可以使用(Swift):
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
Swift 3.0:
Swift 3.0:
let indexPath = IndexPath(row: 0, section: 0)
#2
4
Duplicate of This post
这篇文章重复一遍
I copied the recieved answer here
我在这里复制了收到的答案
For an int index:
对于int索引:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
Creates Index of the item in node 0 to point to as per the reference.
创建节点0中项目的索引以指向根据引用。
To use the indexPath in a UITableView, the more appropriate method is
要在UITableView中使用indexPath,更合适的方法是
NSIndexPath *path = [NSIndexPath indexPathForRow:yourInt inSection:section];
#3
0
You can get indexpath using below code
您可以使用下面的代码获取indexpath
NSIndexPath *index = [NSIndexPath indexPathForRow:YOURINTSTORED inSection:0];