伙计们,我得到这个错误
可变的课程标题从未改变
同时尝试使用“ dequeueReusableCellWithIdentifier”。
这是我的代码:
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
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
var (courseTitle, courseAuthor) = devCourses[indexPath.row]
cell.textLabel?.text = courseTitle
return cell
}
有任何想法吗?
最佳答案
您允许更改courseTitle。将var更改为let:
let (courseTitle, courseAuthor) = devCourses[indexPath.row]
使用Swift开发是一个好主意,始终默认使用let,然后仅在需要进行更改时才更改为var。
关于ios - 可变的类(class)标题从未改变,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35503985/