編輯:花了很多時間看你的項目後,我發現了這個問題。
點擊你的Main.Storyboard文件。點擊文件檢查器。取消選中大小類。完成。您的項目有效!
這似乎是一個XCode錯誤。如果再次檢查Size Classes,你的項目仍然可以工作。
因此,修正是取消選中,然後選中Main.storyboard文件的文件檢查器中的Size Classes。
不過:我的語法的建議仍然有效,它使更清晰的代碼:
好吧,你檢查the solution of the exercise?
有一個在頁面的最後一個環節;)
1差異:
var workouts = [Workout]()
var numbers = [Workout]()
func loadSampleMeals() {
let workouts1 = Workout(name: "Run", number: "1000")!
let workouts2 = Workout(name: "Walk", number: "2000")!
let workouts3 = Workout(name: "Push-Ups", number: "20")!
workouts += [workouts1, workouts2, workouts3]
numbers += [workouts1, workouts2, workouts3]
}
應該是:
var workouts = [Workout]()
func loadSampleMeals() {
let workouts1 = Workout(name: "Run", number: "1000")!
let workouts2 = Workout(name: "Walk", number: "2000")!
let workouts3 = Workout(name: "Push-Ups", number: "20")!
workouts += [workouts1, workouts2, workouts3]
}
第二個區別:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "DhikrTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! GoalsTableViewCell
// Fetches the appropriate meal for the data source layout.
let dhikr = workouts[indexPath.row]
let number = numbers[indexPath.row]
cell.nameLabel.text = dhikr.name
cell.numberLabel.text = number.number
//cell.photoImageView.image = dhikr.photo
//cell.ratingControl.rating = dhikr.rating
return cell
}
應該是:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "DhikrTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! GoalsTableViewCell
// Fetches the appropriate meal for the data source layout.
let dhikr = workouts[indexPath.row]
cell.nameLabel.text = dhikr.name
cell.numberLabel.text = dhikr.number
//cell.photoImageView.image = dhikr.photo
//cell.ratingControl.rating = dhikr.rating
return cell
}
P.S:
class Workout {
// MARK: Properties
var name: String
//var notifications: Int
var number: Int
// MARK: Initialization
init?(name: String, number: Int) {
// Initialize stored properties.
self.name = name
//self.notifications = notifications
self.number = number
// Initialization should fail if there is no name or if the rating is negative.
if name.isEmpty || number < 0{
return nil
}
}
}
number
永遠不會< 0,也許你的意思== 0
?
真的沒有得到你的問題。你在哪裏面臨桌面或addgoals問題,是什麼問題 –
有一個問題?什麼問題? – FredericP
你應該顯示你的代碼(可以上傳到谷歌驅動器並提供鏈接),並確切地說明你面臨的問題。 – Mathews