Ios 如何解决Swift中消失/不可见/空UITableViewCells的问题?

Ios 如何解决Swift中消失/不可见/空UITableViewCells的问题?,ios,swift,uitableview,uitextfield,uipickerview,Ios,Swift,Uitableview,Uitextfield,Uipickerview,我有两个viewcontroller,一个是GoalsViewController,另一个是AddNewGoalViewController GoalsViewController用于删除目标(单元格)和添加新目标(单元格)。有一个UITableView和一个按钮,添加新目标。当用户按下添加新目标按钮时,它将传递到AddNewGoalViewController。在AddNewGoalViewController中,用户将选择训练、通知(他们希望收到通知的次数)以及他们希望跑步、步行或做任何其他

我有两个
viewcontroller
,一个是
GoalsViewController
,另一个是
AddNewGoalViewController

GoalsViewController
用于删除目标(单元格)和添加新目标(单元格)。有一个
UITableView
和一个按钮,添加新目标。当用户按下添加新目标按钮时,它将传递到
AddNewGoalViewController
。在
AddNewGoalViewController
中,用户将选择训练、通知(他们希望收到通知的次数)以及他们希望跑步、步行或做任何其他工作的次数


我检查了一下(点击单词“tutorial”检查一下),这很有帮助。问题是它正在实现空单元格。我的项目需要更好地检查。

编辑:在花了很多时间查看您的项目后,我发现了问题。

单击主.Storyboard文件。单击文件检查器。取消选中大小类。完成。你的项目成功了

这似乎是一个XCode错误。如果您再次检查大小类,您的项目应该仍然有效

因此,修复方法是取消选中Main.storyboard文件的文件检查器中的大小类,然后再选中

尽管如此:我的语法建议仍然有效,它使代码更简洁:

你查过了吗

页面末尾有一个链接;)

第一个区别:

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]
}
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
}
应该是:

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]


    cell.nameLabel.text = dhikr.name
    cell.numberLabel.text = dhikr.number
    //cell.photoImageView.image = dhikr.photo
    //cell.ratingControl.rating = dhikr.rating

    return cell
}
第二个区别:

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]
}
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
}
应该是:

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]


    cell.nameLabel.text = dhikr.name
    cell.numberLabel.text = dhikr.number
    //cell.photoImageView.image = dhikr.photo
    //cell.ratingControl.rating = dhikr.rating

    return cell
}
附言:

课堂锻炼{
//马克:财产
变量名称:String
//var通知:Int
变量编号:Int
//标记:初始化
初始化?(名称:字符串,编号:Int){
//初始化存储的属性。
self.name=名称
//self.notifications=通知
self.number=number
//如果没有名称或评级为负值,初始化应失败。
如果name.isEmpty | | number<0{
归零
}
}
}

number
永远不会<0,也许你的意思是
==0
?。

真的没有明白你的问题。您在tableview或addgoals中面临的问题是什么?问题是什么?有什么问题?你应该显示你的代码(可以上传到谷歌硬盘并提供链接),并准确说明你面临的问题。即使下载了代码,我仍然无法理解你的问题。您尚未在goalViewController中为tableView添加任何数据源或委托。此外,在AddNewGoalsViewController中,您还没有为UIButton的操作添加任何代码。你想给我们解释什么?你能帮我更新一下吗?我试着查了查你的代码,但是信息太少了。需要你的故事板来理解你需要什么。@Emini我很乐意帮助你^^