gpt4 book ai didi

ios - 来自 XIB 错误的 UITableView 和 UITableViewCell?

转载 作者:行者123 更新时间:2023-11-28 07:17:25 25 4
gpt4 key购买 nike

我正在尝试以编程方式使用 .xib 中的 UITableViewCell 制作 UITableView。但我不知道我做错了什么。我已经阅读了几个教程,看起来我做的一切都很好,但它不起作用。你们能帮帮我吗?

这就是我加载 UITableView 和 Cell 的方式

import Foundation
import UIKit
class GamesViewController : UIViewController, UITableViewDelegate,UITableViewDataSource
{

var gameTableView : UITableView?;

override func viewDidLoad()
{
gameTableView = UITableView(frame: self.view.frame, style: UITableViewStyle.Plain);
gameTableView!.delegate = self;
gameTableView!.dataSource = self;
gameTableView!
var nib = UINib(nibName: "TaskCellView", bundle: nil);
gameTableView!.registerNib(nib, forCellReuseIdentifier: "Cell");

self.view.addSubview(gameTableView);

super.viewDidLoad();

}

override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning();
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
{

}

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
return 4
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? TaskCell;
cell!.taskSkillLabel.text = "sdfsdf";
return cell;
}
}

这是我的自定义 View 单元格

import Foundation
import UIKit

class TaskCell : UITableViewCell
{
@IBOutlet var taskSkillLabel : UILabel;

init(style: UITableViewCellStyle, reuseIdentifier: String!)
{

super.init(style: UITableViewCellStyle.Default, reuseIdentifier: reuseIdentifier);
}

}

我无法发布图片,但最终我的细胞彼此重叠......和奇怪的人工制品。我什至下载了具有类似工作示例的某人的代码,情况非常相似。

最佳答案

另加

func tableView(tableView: UITableView!,heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
{
return ATLEAST_YOUR_CELL_HIGHT
}

关于ios - 来自 XIB 错误的 UITableView 和 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24951949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com