Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中具有自定义单元格的TableViewController_Ios_Uitableview_Swift - Fatal编程技术网

Ios 在swift中具有自定义单元格的TableViewController

Ios 在swift中具有自定义单元格的TableViewController,ios,uitableview,swift,Ios,Uitableview,Swift,我对Swift中的自定义TableViewCell有问题。我试图在TableView中显示customeTableViewCell,但效果不好。我在屏幕上看到一个灰色的正方形。。。我在网上找到了一些建议禁用自动布局的答案。我做了,但是现在,我的手机显示出来了,但是手机的高度有点乱。正如您所看到的,我的单元格应该有红色背景,它显示在3个单元格的高度上,而背景仅显示在1个单元格上。单元格高度和行高度均设置为150px With Auto-Layout:

我对Swift中的自定义
TableViewCell
有问题。我试图在
TableView
中显示custome
TableViewCell
,但效果不好。我在屏幕上看到一个灰色的正方形。。。我在网上找到了一些建议禁用自动布局的答案。我做了,但是现在,我的手机显示出来了,但是手机的高度有点乱。正如您所看到的,我的单元格应该有红色背景,它显示在3个单元格的高度上,而背景仅显示在1个单元格上。单元格高度和行高度均设置为150px

           With Auto-Layout:                   Without Auto-Layout:

以下是单元格代码:

class CharacterDescription : UITableViewCell {
    @IBOutlet var imageProfile: UIImageView!
    @IBOutlet var name: UILabel!
    @IBOutlet var hp: UILabel!
    @IBOutlet var damages: UILabel!
    @IBOutlet var range: UILabel!
    @IBOutlet var mp: UILabel!
    @IBOutlet var critChances: UILabel!
    @IBOutlet var critModifier: UILabel!

    required init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
        super.init(style: UITableViewCellStyle.Value1, reuseIdentifier: reuseIdentifier)
    }
}
以及
TableViewController
代码:

class CharacterDescriptionsViewController : UITableViewController, UITableViewDataSource, UITableViewDelegate {
    var userProfile: UserProfile!

    required init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
    }

    override init() {
        super.init()
    }

    override func viewDidLoad() {
        var nibName = UINib(nibName: "CharacterDescription", bundle:nil)

        self.tableView.registerNib(nibName, forCellReuseIdentifier: "CharacterDescription")
    }

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

    override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
        return userProfile.characters!.count
    }


    override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
        var cell = self.tableView.dequeueReusableCellWithIdentifier("CharacterDescription", forIndexPath: indexPath) as CharacterDescription

        //!TODO: Init of cell
        return cell
    }
}

您必须覆盖
TableView.heightforrowatinexpath
以返回自定义单元格的高度。

电视单元格的高度是多少?抱歉,我刚刚注意到发布帖子时出现问题。视图高度(TVCell的)和行高度都设置为150px