그래서 다른 이미지를 tableview 셀에 넣고 싶습니다. 3 개의 다른 파일이 있습니다. 이미 코딩을했는데 문제가 있습니다. 제발, 제 코드를보고이 마약 쟁이를 다루는 법을 가르쳐주세요. (하루 종일 꼼짝하지 마라.) ... 이것의 요지는 사용자 정의 셀에 다른 이미지와 라벨 두 개가있는 것입니다.테이블보기 다른 데이터가있는 사용자 정의 셀
먼저 파일
class MenuCells {
private var _cellTitle: String
private var _cellDetails: String
private var _cellIcon: Array<String>
var cellTitle: String {
return _cellTitle
}
var cellDetails: String {
return _cellDetails
}
var cellIcon: Array<String> {
return _cellIcon
}
init(cellTitle: String, cellDetails: String, cellIcon: Array<String>) {
_cellTitle = cellTitle
_cellDetails = cellDetails
_cellIcon = cellIcon
}
func cellData() {
_cellTitle = "x"
_cellDetails = "y"
_cellIcon = ["1","2","3","4"]
}
}
두 번째 파일
class MenuCell: UITableViewCell {
@IBOutlet weak var bg: UIView!
@IBOutlet weak var cellTitle: UILabel!
@IBOutlet weak var cellDetails: UILabel!
@IBOutlet weak var cellIcon: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}
func configureCell(menuCell: MenuCells) {
cellTitle.text = menuCell.cellTitle
cellDetails.text = menuCell.cellDetails
cellIcon.image = UIImage(named: "\(menuCell.cellIcon)")
}
}
세 번째 파일 (여기서 임 붙어, 나는 데이터를 구현하는 방법을 잘 모릅니다)
import UIKit
class MenuVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableMenu: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableMenu.delegate = self
tableMenu.delegate = self
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "menuCell", for: indexPath) as? MenuCell
return cell
}
}
코드가 완벽합니다. 거의 –
viewDidLoad는'tableMenu.delegate = self'를 두 번 설정하고 그 모양으로는 dataSource를 설정하지 않았습니다. 해당 라인 중 하나를'tableMenu.dataSource = self'로 대체하거나 연결 관리자를 통해 스토리 보드의 ViewController에 연결하여 dataSource를 설정해보십시오. –