简体   繁体   English

从XIB的UITableView和UITableViewCell错误?

[英]UITableView and UITableViewCell from XIB bug?

I'am trying to make UITableView with UITableViewCell from .xib programatically. 我正在尝试以编程方式从.xib使用UITableViewCell创建UITableView But I don't know what I'am doing wrong. 但是我不知道我在做什么错。 I have read couple of tutorials and it's looks like I'am doing everything ok, but it doesn't work. 我已经阅读了几本教程,看起来我一切都很好,但是没有用。 Can you guys help me? 你们能帮我吗?

That's how I'am loading UITableView and Cell 这就是我加载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;
}
 }

And this is my custom view cell 这是我的自定义视图单元格

import Foundation
import UIKit

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

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

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

}

I can not post images but I end up with my cells one on each other.. and strange artefacts. 我无法发布图像,但最终我的单元格彼此重叠..和奇怪的假象。 I even download someones code with similar working sample and situation is very similar. 我什至下载了具有类似工作示例的代码,情况也非常相似。

Also add 还添加

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