我有两个ViewControllers
,一个是GoalsViewController
,另一个是AddNewGoalViewController
。
GoalsViewController
对于删除目标(单元格)和添加新目标(单元格)非常有用。有一个UITableView
和一个按钮,添加新目标。当用户按下添加新目标按钮时,它将转到AddNewGoalViewController
。在AddNewGoalViewController
用户将选择锻炼,通知(他们想要通知的次数),以及他们想要跑步,走路或做任何其他工作的次数。
我检查了a tutorial(点击“教程”一词进行检查),这很有帮助。问题是它正在实现空单元格。 Download我的项目更好地检查它。
答案 0 :(得分:3)
编辑:在花了很多时间研究您的项目之后,我发现了这个问题。
单击您的Main.Storyboard文件。单击文件检查器。取消选中大小类。完成。你的项目有效!
这似乎是一个XCode错误。如果再次检查大小类,您的项目仍然可以工作。
因此,修复程序取消选中,然后在Main.storyboard文件的File Inspector中检查Size Classes。
NONETHELESS:我的语法建议仍然有效,它可以提供更清晰的代码:
嗯,您检查了how can i get text formatting with iTextSharp 吗?
页面末尾有一个链接;)
第一个差异:
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
永远不会&lt; 0,也许你的意思是== 0
?。