如何在iOS中显示自定义嵌套列表 [英] How to show custom nested lists in iOS

查看:179
本文介绍了如何在iOS中显示自定义嵌套列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS中显示一个列表,该列表本身将包含一个列表. 例如,我想创建一个按日排列的任务列表,其中的日期和任务是动态的,因此外部列表为DAY LIST,内部列表为TASK LIST.也想处理对TASKS的单击. 如何在iOS中实现此功能,尝试使用Table Views但由于要显示嵌套列表而无法实现.总之,我想在iOS中显示列表的列表.

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.

推荐答案

    //
    //  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()

        }
    }

这篇关于如何在iOS中显示自定义嵌套列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆