How to use an enum and switch() with UITableViewController in Swift

后端 未结 3 1021
刺人心
刺人心 2021-01-13 17:51

My UITableView has two sections, so I created an enum for them:

private enum TableSections {
    HorizontalSection,
    VerticalSection
}

H

3条回答
  •  长情又很酷
    2021-01-13 17:58

    Ok, I figured it out, thanks @tktsubota for pointing me in the right direction. I'm pretty new to Swift. I looked into .rawValue and made some changes:

    private enum TableSections: Int {
        case HorizontalSection = 0
        case VerticalSection = 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
        switch section {
    
        case TableSections.HorizontalSection.rawValue:
            return firstArray.count
    
        case TableSections.VerticalSection.rawValue:
            return secondArray.count
    
        default 
            return 0
        }
    }
    

提交回复
热议问题