伙计我收到此错误
可变课程标题从未发生变异
尝试使用' dequeueReusableCellWithIithntifier '时。
这是我的代码:
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
}
有什么想法吗?
答案 0 :(得分:1)
您允许更改courseTitle。将var更改为let:
let (courseTitle, courseAuthor) = devCourses[indexPath.row]
使用Swift开发时,默认情况下始终使用let是一个好主意,如果需要进行更改,则只需更改为var。
答案 1 :(得分:0)
将var更改为let,因为您没有改变courseTitle或courseAuthor的值。
let courseInfo = devCourses[indexPath.row]
cell.textLabel?.text = courseInfo.0