UITableView, how do I know what Section during cellForRowAtIndexPath?

前端 未结 3 1355
隐瞒了意图╮
隐瞒了意图╮ 2021-02-03 16:39

I have a UITableView displaying a list of Cities. I want to separate them by State. I can\'t seem to figure out how to get it to pick the right items out of my Array. If Sectio

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 17:38

    Swift 3, 4 and 4.2

    Using Switch

    switch indexPath.section {
            case 0:
                print("Write your code for section number one.")
            case 1:
                print("Write you code for section number two")
            default:
                return
            }
    

    Using if else

    if indexPath.section == 0 {
                print("Write your code for section number one.")
            } else if indexPath.section == 1 {
                print("Write your code for section number two.")
            }
    

提交回复
热议问题