【发布时间】:2015-07-27 20:01:20
【问题描述】:
大家好,我是 Swift 和 iOS 编程的新手,我正在尝试创建我的第一个应用程序。我目前正在尝试将数组加载到表视图中,但未加载该数组。我不太确定如何检查,但我一直在关注这个 youtube 视频 https://www.youtube.com/watch?v=pR6dR-vVZeY ,大部分情况下并对其进行调整以适合我的情况。我也没有收到任何错误。这是我的代码。 导入 UIKit
class routineTableViewController: UITableViewController {
var routines = [Routine]();
override func viewDidLoad() {
super.viewDidLoad()
var routines: [Routine] = [];
var phatRoutine = Routine(nameOfRoutinex: "PHAT by Layne Norton", typeOfRoutinex: "Mixed");
routines.append(phatRoutine)
var smolovRoutine = Routine(nameOfRoutinex: "Smolov", typeOfRoutinex: "Strength");
routines.append(smolovRoutine)
for Routine in routines {
println(Routine.nameOfRoutine);
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return routines.count;
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var Cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell;
Cell.textLabel?.text = routines[indexPath.row].nameOfRoutine;
return Cell;
}
}
我正在检查我是否真的使用 for 循环将元素添加到例程中,它说我是。不太确定从这里去哪里。这也是我的故事板,我也不确定是否完全正确。
谢谢你们的帮助。
【问题讨论】:
标签: ios arrays xcode uitableview