Ich weiß hoffentlich, dass die Klasse NSIndexPath Arrays mit Arrays behandelt.NSIndexPath in Swift
Ich habe diesen Code:
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let devCourses = [
("iOS App Dev with Swift Essential Training","Simon Allardice"),
("iOS 8 SDK New Features","Lee Brimelow"),
("Data Visualization with D3.js","Ray Villalobos"),
("Swift Essential Training","Simon Allardice"),
("Up and Running with AngularJS","Ray Villalobos"),
("MySQL Essential Training","Bill Weinman"),
("Building Adaptive Android Apps with Fragments","David Gassner"),
("Advanced Unity 3D Game Programming","Michael House"),
("Up and Running with Ubuntu Desktop Linux","Scott Simpson"),
("Up and Running with C","Dan Gookin") ]
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return devCourses.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()
let (courseTitle, courseAuthor) = devCourses[indexPath.row]
cell.textLabel?.text = courseTitle
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Was ich nicht verstehe, wie NSIndexPath funktioniert. Ich habe die Dokumentation gelesen, aber ist es für mich immer noch zu schwer zu verstehen, wie das funktioniert. Wie kann ich wissen, dass NSIndexPath Eigenschaft der Zeile hat? Cans jemand jeden Teil dieser Zeile bitte erklären:
let (courseTitle, courseAuthor) = devCourses[indexPath.row]
Wie NSIndexPath wissen, dass courseTitle in dieser Konstante Index Indexnummer 0 whitin Array bezieht sich 0 ("iOS App Dev with Swift Essential Training","Simon Allardice")
In der Swift-Dokumentation nach "Tupel" suchen. –
Xcode hat einige nette Funktionen, die Ihnen helfen, den Code zu verstehen, den Sie betrachten. Klicken Sie in Xcode bei gedrückter Wahltaste in der obigen Anweisungszeile auf "row", um anzuzeigen, worum es sich handelt. Wenn Sie im Popup auf "NSIndexPath UIKit Additions" neben "Referenz" klicken, wird die Dokumentation angezeigt. – vacawama