gpt4 book ai didi

ios - 找不到单元格标识符(没有 Storyboard)

转载 作者:行者123 更新时间:2023-11-28 06:01:36 24 4
gpt4 key购买 nike

您好,我遇到了一个问题,我似乎无法找到要放入表格中的单元格标识符。我有 5 个文件。我是 xcode 的新手,但我需要在没有 Storyboard的情况下为我的学校项目编写代码。

我正在按照这里的教程 - https://www.youtube.com/watch?v=kYmZ-4l0Yy4

ActiveCasesController.swift

//
// ActiveCasesController.swift
//
// Created by fypj on 29/3/18.
// Copyright © 2018 fypj. All rights reserved.
//

import UIKit

class ActiveCasesController:UIViewController, UITableViewDelegate, UITableViewDataSource {

let elements = ["horse", "cat", "dog", "potato","horse", "cat", "dog", "potato","horse", "cat", "dog", "potato"]


var acView = ActiveCasesView()

override func viewDidLoad() {
super.viewDidLoad()

setupView()
acView.tableView.delegate = self
acView.tableView.dataSource = self
}

func setupView() {
let mainView = ActiveCasesView(frame: self.view.frame)
self.acView = mainView
self.view.addSubview(acView)
acView.setAnchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return elements.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell:ActiveCaseCellView = tableView.dequeueReusableCell(withIdentifier: "customCell") as! ActiveCaseCellView

cell.cellView.layer.cornerRadius = cell.cellView.frame.height / 2

cell.lblCell.text = elements[indexPath.row]
return cell
}


}

ActiveCasesView.swift

import UIKit

class ActiveCasesView: UIView{

@IBOutlet var mainView: UIView!
@IBOutlet weak var tableView: UITableView!

override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
//scrollView()
}

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

private func commonInit(){
Bundle.main.loadNibNamed("ACView", owner: self, options: nil)
addSubview(mainView)
mainView.frame = self.bounds
mainView.autoresizingMask = [.flexibleHeight,.flexibleWidth]
}
}

ACView.xib

enter image description here

ActiveCaseCellView.swift

import UIKit

class ActiveCaseCellView:UITableViewCell {


@IBOutlet weak var cellView: UIView!
@IBOutlet weak var lblCell: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}

ACViewCell.xib

enter image description here

错误信息

enter image description here

我添加注册的图片不确定我是否添加正确..

enter image description here

最佳答案

enter image description here

use the cell identifier by selecting you cell in storyboard.
it must be same in viewcontroller and storyboard tableview cell.

关于ios - 找不到单元格标识符(没有 Storyboard),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49549509/

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