未在swift中的自定义tableview单元格中显示的数据已添加下面的单元格类 [英] Data not showing in custom tableview cell in swift have added the cell class below

查看:178
本文介绍了未在swift中的自定义tableview单元格中显示的数据已添加下面的单元格类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有可能但我仍然无法弄清楚为什么数据不会显示在自定义单元格中。它在 subTitle 单元格中看起来很好, println 确认数据在那里。我已经检查了标识符和 IBOutlets 100次:

I have tried everything possible but I still can't figure out why the data is not shown in a custom cell. It looks fine in a subTitle cell and println confirms the data is there. I have checked the identifier and the IBOutlets a 100 times:

//  ActivityDetailsTableViewController.swift
//  TestActForm
//
//  Created by Jeremy Andrews on 2015/08/08.
//  Copyright (c) 2015 Jeremy Andrews. All rights reserved.
//

import UIKit

class ActivityDetailsTableViewController: UITableViewController
{

    var activities: [Activity] = activityProfile

    override func viewDidLoad() 
    {
        super.viewDidLoad() 
    }

    override func didReceiveMemoryWarning() 
    {
        super.didReceiveMemoryWarning()
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int 
    {   
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    {
        return activities.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell 
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("ActivityDetail", forIndexPath: indexPath) as! ActivityDetailCell
        let activity = activities[indexPath.row] as Activity
        println(activity.question)
        cell.questionLabel?.text = activity.question
        cell.answerLabel?.text = activity.answer
        println(cell.questionLabel.text)
        return cell
    }

}

import UIKit

class ActivityDetailCell: UITableViewCell 
{
    @IBOutlet weak var questionLabel: UILabel!
    @IBOutlet weak var answerLabel: UILabel!


    override func awakeFromNib() 
    {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) 
    {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }  
}


推荐答案

cell.questionLabel?.text = activity.question
cell.answerLabel?.text = activity.answer

如果未创建这些标签,此代码将无提示失败。我打赌你没有通过故事板中的IBOutlets连接它们。

this code would fail silently if these label are not created. I bet you did not hook them up via IBOutlets in your storyboard.

这篇关于未在swift中的自定义tableview单元格中显示的数据已添加下面的单元格类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆