У меня есть табличное представление с кнопкой в каждой ячейке. Когда это срабатывает, у меня есть функция didselectrow. Я хочу использовать свой индексный путь для получения значения из массива, который дает содержимое ячеек. Как я могу преобразовать этот NSIndexpath в int для использования в массиве?swift, convert NSIndexpath to Int
4
A
ответ
11
Скорее всего, что вы хотите, это строка. Вы можете увидеть example here.
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
let alert = UIAlertController(title: "Item selected", message: "You selected item \(indexPath.row)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK",
style: UIAlertActionStyle.Default,
handler: {
(alert: UIAlertAction!) in println("An alert of type \(alert.style.hashValue) was tapped!")
}))
self.presentViewController(alert, animated: true, completion: nil)
}
+1
По иронии судьбы, я обнаружил ваш вопрос, ища ответ на это сам. –
1
Используйте IndexPath.row, см. Ниже, например.
Листинг (IndexPath: 316-319)
/// The row of this index path, when used with `UITableView`.
///
/// - precondition: The index path must have exactly two elements.
public var row: Int
Пример
let name : String = (indexPath.row>0) ? "Bob" : "Sam";
Справочник
Смежные вопросы
- 1. convert int to wstring
- 2. convert string [] to int []
- 3. Convert int [] to boolean []
- 4. Convert char * to int
- 5. Convert distanceFromLocation to Int
- 6. Convert Float to Int
- 7. Convert Byte [] to int
- 8. convert double to int
- 9. Convert Int To Hex
- 10. Как конвертировать NSIndexPath в Int в Swift?
- 11. Arduino Convert int to Char
- 12. SQL convert INT to datetime
- 13. Convert Integer [] to int [] array
- 14. SQL convert int to time
- 15. SSIS Convert NVARCHAR to Int
- 16. C# convert .value to int
- 17. C convert int to string
- 18. convert const char * to int
- 19. Python-Convert int to bin
- 20. Convert Maybe Int to Int в Haskell
- 21. haskell Convert IO Int to Int System.Random.MWC
- 22. Convert UInt8 ?, String, Int to String type using Swift
- 23. Swift convert string to date
- 24. Swift convert NSError to String
- 25. Convert Objective C to Swift
- 26. Convert NSDictionary to Swift Dictionary
- 27. Struct convert to xml (Swift)
- 28. C++ Convert Ascii Int To Char To Int
- 29. xcode swift AnyObject to Swift convert
- 30. NSIndexPath in Swift
indexPath.Row. IndexPath - это NSIndexPath. – ericgu