ios - 获取 indexPath.row 的字符串值

标签 ios uitableview swift

这两种获取indexPath.row字符串值的方式有什么区别?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var newString: String = String(indexPath.row)
    var newString2: String = indexPath.row.description)
}

最佳答案

description属性用来表示any的内容NSObject或任何实现 Printable 的类/结构/枚举字符串格式的协议(protocol),尽管在 Int 的情况下( indexPath.rowInt )它只返回数字的字符串值,你不应该用它来转换 IntString .有可能在 Swift 的 future 版本中 description属性将返回类似“Int:[value]”的内容。 你应该使用 String(indexPath.row)相反。

关于ios - 获取 indexPath.row 的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29108199/

相关文章:

ios - 代号一中的 BackgroundFetch

ios - 在 Storyboard 中查看数组 MxN 的方法 - Swift 3- Xcode 8.2.1

ios - 将选定的 UITableViewCell 带回原来的位置

ios - Swift 4 从 UITableView 执行 segue 并传递数据

objective-c - 点击时返回标签的标签

iOS Toggles 不会在 View Controller 之间保留它们的状态

iphone - iPhone 4.3 Tableview 中的多个单元格选择

ios - 使用 UIButton 从其他 UIViewController 中删除一行

快速异步网络。出现错误时如何重试?

json - 在 Swift 4 中解析 NiceHash JSON