gpt4 book ai didi

ios - 无法将类型 'CustomProfileCell' 的返回表达式转换为返回类型 'UITableViewCell'

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:58 26 4
gpt4 key购买 nike

这是我的代码

//
// FirstViewController.swift
// tabbed
//
// Created by 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, 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 tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profileArray.count
}
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()

}

}

我不断得到

Cannot convert return expression of type 'CustomProfileCell' to return type 'UITableViewCell'

enter image description here

最佳答案

由于您应该返回类型为 UITableViewCell 的自定义类,因此只有在以下情况下才会编译返回

class CustomProfileCell : UITableViewCell {
// here outlets hooked to xib
}

关于ios - 无法将类型 'CustomProfileCell' 的返回表达式转换为返回类型 'UITableViewCell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51450025/

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