How to show custom nested lists in iOS

旧巷老猫 提交于 2019-12-12 04:55:35

问题


I want to show a list in iOS that itself will contain a list. For example I want to create a day wise task list in which the day and task are dynamic.So outer list is DAY LIST and inner list would be TASK LIST.Also want to handle the click on TASKS. How can I achieve this in iOS, have tried using Table Views but cannot achieve it since I want to show nested list.In short I want to show a list of list in iOS.


回答1:


    //
    //  ViewController.swift
    //  Ishika
    //
    //  Created by IShika on 12/06/17.
    //  Copyright © 2017 Ishika. All rights reserved.
    //

    import UIKit

    class ViewController: UIViewController {
        @IBOutlet weak var viewForHeader: UIView!

        @IBOutlet weak var tblViewForHome: UITableView!
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
        }



    }
    extension ViewController: UITableViewDataSource,UITableViewDelegate{

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

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

            var cell = UITableViewCell()

                cell = tblViewForHome.dequeueReusableCell(withIdentifier: "FeaturedLocationsCell") as! FeaturedLocationCellClass

                   return cell
        }

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

            //It should be greater than your collectionViewCell's size
            return 300.0
        }
    }

    //MARK:- UITABLEVIEWCELL CLASS


    class FeaturedLocationCellClass : UITableViewCell,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
        @IBOutlet weak var colVForFeaturedLocations: UICollectionView!

        override func awakeFromNib() {

            super.awakeFromNib()
            colVForFeaturedLocations.dataSource = self
            colVForFeaturedLocations.delegate = self


        }
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return 2
        }
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell = colVForFeaturedLocations.dequeueReusableCell(withReuseIdentifier: "myFeautredLocationColVCell", for: indexPath) as! MyFeaturedLocationCollCellClass
            return cell
        }

        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{

            return CGSize(width: screenWidth/2 + 50 , height: screenWidth/2 + 50)
        }



    }


    //MARK:- UICOLLECTIONVIEWCELL CLASS
    class MyFeaturedLocationCollCellClass: UICollectionViewCell{
    //Can draw outlets for your collectionView elements


        override func awakeFromNib() {
            super.awakeFromNib()

        }
    }


来源:https://stackoverflow.com/questions/46192271/how-to-show-custom-nested-lists-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!