如何在iOS中显示自定义嵌套列表
问题描述:
我想在iOS中显示自己将包含列表的列表。 例如,我想创建一个日期明确的任务列表,其中日期和任务是动态的。所以外部列表是日期列表,内部列表将是任务列表。也希望处理点击任务。 如何在iOS中实现这一点,尝试使用表视图,但无法实现它,因为我想显示嵌套列表。简而言之,我想在iOS中显示列表的列表。如何在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()
}
}
+0
@ Ishika-谢谢!我也参考了这个[TableView中的CollectionView](https://github.com/ashfurrow/Collection-View-in-a-Table-View-Cell) –
+0
它的我的荣幸:) – Ishika
你可以在tableView里面使用tableView或tableView里面的collectionview。如果您可以分享正确要求的图像,我可以帮助您更多。 – Ishika
你可以在tableview –
目标C或swift中共享任何使用tableview的参考吗? – Ishika