繁体   English   中英

从XIB的UITableView和UITableViewCell错误?

[英]UITableView and UITableViewCell from XIB bug?

我正在尝试以编程方式从.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;
}
 }

这是我的自定义视图单元格

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM