ios - 尝试将自定义单元格添加到 TableView 时出错

标签 ios xcode uitableview xcode9

我正在尝试将自定义单元格添加到我的表格 View 中

这是我为自定义 CustomProfileView.xib 文件配置的内容

enter image description here

主 Storyboard

enter image description here

我不断得到

Use of undeclared type 'CustomProfileCell'

这是我的全部代码

//
//  FirstViewController.swift
//  tabbed
//
//  Created by Ben Heng on 7/18/18.
//  Copyright © 2018 LR Web Design. All rights reserved.
//

import UIKit

class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var profileTableView: UITableView!

    var profileArray = [Profile]()

    override func viewDidLoad() {
        super.viewDidLoad()

        profileTableView.delegate = self
        profileTableView.dataSource = self
        profileTableView.register(UINib(nibName: "ProfileCell",bundle: nil) , forCellReuseIdentifier: "CustomProfileCell")

        retrieveProfiles()

    }



    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return profileArray.count
    }

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


        let cell = tableView.dequeueReusableCell(withIdentifier: "customProfileCell", for: indexPath) as! CustomProfileCell

        cell.profileImage.image = UIImage(named: profileArray[indexPath.row].profileImage)
        cell.profileName.text = profileArray[indexPath.row].name
        cell.deviceCount.text = profileArray[indexPath.row].deviceCount

        return (cell)
    }



    func retrieveProfiles() {

        let p1 = Profile()
        p1.name = "John"
        p1.deviceCount = "10"
        p1.profileImage = "john"
        profileArray.append(p1)

        let p2 = Profile()
        p2.name = "Jane"
        p2.deviceCount = "5"
        p2.profileImage = "jane"
        profileArray.append(p2)

        let p3 = Profile()
        p3.name = "Andrew"
        p3.deviceCount = "4"
        p3.profileImage = "andrew"
        profileArray.append(p3)

        self.profileTableView.reloadData()


    }

}

最佳答案

根据您的 swift 名称 CustomProfileViewCell

let cell = tableView.dequeueReusableCell(withIdentifier: "customProfileCell", for: indexPath) as! CustomProfileViewCell

//

profileTableView.register(UINib(nibName: "CustomProfileViewCell",bundle: nil) , forCellReuseIdentifier: "customProfileCell")

关于ios - 尝试将自定义单元格添加到 TableView 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51449627/

相关文章:

ios - 禁用 UITableView 离屏渲染

ios - dequeueReusableCellWithIdentifier 一直返回 nil

ios - FBSDKAccessToken currentAccessToken 登录后未更新

ios - UITableView - 如何滚动标题部分以及表格 View 单元格?

ios - Apple Pay 是否需要与新的 iOS 应用程序集成?

ios - 有人有 iOS9 的工作审查链接吗?

ios - 如何映射 API?

iphone - UITableView 旋转后的垂直反弹(contentView?)

ios - 在 PickerView 中设置行标题

ios - 如何根据设备更改 View 高度? (xcode)