Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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 为什么我';我们建立了一个原型细胞,但什么都没有出现?_Ios_Iphone_Xcode_Swift - Fatal编程技术网

Ios 为什么我';我们建立了一个原型细胞,但什么都没有出现?

Ios 为什么我';我们建立了一个原型细胞,但什么都没有出现?,ios,iphone,xcode,swift,Ios,Iphone,Xcode,Swift,我通过情节提要将tableView添加到ViewController中的视图中 然后我在我的原型单元格中添加一个按钮。空白的TabLVIEW确实显示出来,但没有按钮。 提前谢谢。删除这一行,您的代码应该可以工作。这里您不需要注册类 class DemoTableController: UIViewController,UITableViewDataSource,UITableViewDelegate { @IBOutlet weak var answerView: UITableView! o

我通过情节提要将tableView添加到ViewController中的视图中

然后我在我的原型单元格中添加一个按钮。空白的TabLVIEW确实显示出来,但没有按钮。
提前谢谢。

删除这一行,您的代码应该可以工作。这里您不需要注册类

class DemoTableController: UIViewController,UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var answerView: UITableView!
override func viewDidLoad() {
    super.viewDidLoad()
    answerView.delegate = self
    answerView.dataSource = self
    answerView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")



}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.

    return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 5
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell

    // Configure the cell...

    return cell
}

请确保在情节提要中正确设置标识符

它必须与您在以下行中的内容相同:

 answerView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")

此外,您可能不需要在tableView(在viewDidLoad中)上使用
registerClass
方法。

如果您使用tableView单元格的自定义类,则应该使用Auto Layout explained。您可能需要注册。如果您使用默认的
UITableviewCell
,则不需要注册。删除registerClass有效。但是为什么呢?谢谢你们,你们帮了大忙。当直接在原型单元中工作(并且没有自定义单元类/nib)时,不需要它。如果单元类是用代码编写的,则必须使用registerClass:方法注册它(以便重用),否则,如果单元是通过nib文件创建的,则使用registerInB:方法注册它。
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell