'HomePageVCNEW' 对协议(protocol) 'UITableViewDelegate' 的快速冗余一致性

标签 swift

它给出了一个错误 UITableViewDataSource, UITableViewDelegate

“HomePageVCNEW”与协议(protocol)“UITableViewDelegate”的冗余一致性

import UIKit

class HomePageVCNEW: UITableViewController, UITableViewDataSource, UITableViewDelegate {


    var arrayofCellData = [cellData]()

    @IBOutlet var tableview: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()


         arrayofCellData = [cellData(cell: 1,DisplayNameText: "TOM",StatusSubtitleText: "Tom's subtitle",ProfileImage:#imageLiteral(resourceName: "mark1"),AccountTypeImage:#imageLiteral(resourceName: "icon-72x72"),MoreOptionsImage: #imageLiteral(resourceName: "ADD BUTTON CENTRED")),cellData(cell: 2,DisplayNameText: "Ben",StatusSubtitleText: "Ben's subtitle",ProfileImage:#imageLiteral(resourceName: "tom3"),AccountTypeImage:#imageLiteral(resourceName: "B icon 72x72"),MoreOptionsImage: #imageLiteral(resourceName: "ADD BUTTON CENTRED")),cellData(cell: 1,DisplayNameText: "liam",StatusSubtitleText: "liam's subtitle",ProfileImage:#imageLiteral(resourceName: "denis2"),AccountTypeImage:#imageLiteral(resourceName: "icon-72x72"),MoreOptionsImage: #imageLiteral(resourceName: "ADD BUTTON CENTRED"))]

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

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



    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return arrayofCellData.count
    }

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



        if
        arrayofCellData[indexPath.row].cell == 1{


            let cell = self.tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
                as! CustomCell



            cell.ProfileImage.image = arrayofCellData[indexPath.row].ProfileImage
            cell.MoreOptionsImage.image = arrayofCellData[indexPath.row].MoreOptionsImage
            cell.AccountTypeImage.image = arrayofCellData[indexPath.row].AccountTypeImage
            cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].DisplayNameText
            cell.SubtitleStatusLabel.text = arrayofCellData[indexPath.row].StatusSubtitleText

            return cell


        }else if arrayofCellData[indexPath.row].cell == 2{

            let cell = self.tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
                as! CustomCell

            cell.ProfileImage.image = arrayofCellData[indexPath.row].ProfileImage
            cell.MoreOptionsImage.image = arrayofCellData[indexPath.row].MoreOptionsImage
            cell.AccountTypeImage.image = arrayofCellData[indexPath.row].AccountTypeImage
            cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].DisplayNameText
            cell.SubtitleStatusLabel.text = arrayofCellData[indexPath.row].StatusSubtitleText

            return cell

        }else{



            let cell = self.tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
                as! CustomCell


            cell.ProfileImage.image = arrayofCellData[indexPath.row].ProfileImage
            cell.MoreOptionsImage.image = arrayofCellData[indexPath.row].MoreOptionsImage
            cell.AccountTypeImage.image = arrayofCellData[indexPath.row].AccountTypeImage
            cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].DisplayNameText
            cell.SubtitleStatusLabel.text = arrayofCellData[indexPath.row].StatusSubtitleText
            return cell





    }


    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {




        if arrayofCellData[indexPath.row].cell == 1{
            return 49






       }else if arrayofCellData[indexPath.row].cell == 2{
            return 49





        }else{
     return 49








        }

    }

}


}//class

最佳答案

当一个类继承自 UITableViewController 时,它默认符合 UITableViewDataSourceUITableViewDelegate,您无需指定它。尝试在 UITableViewController

之后删除 UITableViewDataSourceUITableViewDelegate

关于 'HomePageVCNEW' 对协议(protocol) 'UITableViewDelegate' 的快速冗余一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44344020/

相关文章:

swift - 在包含 UIImageView 的 UICollectionView 单元格中的 UIImage 之间切换

ios - 将字典数组传递给函数的问题

ios - 在observeSingleEvent 中变量的值没有改变

iOS9 sendSynchronousRequest 弃用

ios - 如何根据区域设置仅显示日期的日期和月份?

swift - Xcode 7-CocoaPod AlamoFire 及其他,导入到项目中但不在项目内部工作

ios - 如何识别 Xcode UI 测试中的控制中心元素?

ios - IQKeyboardManager问题,UIViewController顶部重叠状态栏

ios - 降低约束的优先级到底有什么作用?

ios - 使用 WebKit 加载 YouTube 视频时控制台中打印警告