2017-09-13 108 views
0

我想在iOS中顯示自己將包含列表的列表。 例如,我想創建一個日期明確的任務列表,其中日期和任務是動態的。所以外部列表是日期列表,內部列表將是任務列表。也希望處理點擊任務。 如何在iOS中實現這一點,嘗試使用表視圖,但無法實現它,因爲我想顯示嵌套列表。簡而言之,我想在iOS中顯示列表的列表。如何在iOS中顯示自定義嵌套列表

+1

你可以在tableView裏面使用tableView或tableView裏面的collectionview。如果您可以分享正確要求的圖像,我可以幫助您更多。 – Ishika

+1

你可以在tableview –

+0

目標C或swift中共享任何使用tableview的參考嗎? – Ishika

回答

2
// 
    // 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