集合视图不能在ios swift中使用Autoresize Row在TableViewCell中打印

时间:2016-11-21 09:00:36

标签: ios swift uicollectionview

问题陈述:需要在表格视图单元格中打印的集合视图以及自动调整大小也应该起作用 感谢

有一个表格视图单元格。 需要打印集合视图。 在没有Collection View的情况下,自动调整Table View单元格的大小 添加集合视图后,它不起作用。 如果使用heightOfRow方法的单元格高度,则打印集合视图 但是如果没有使用它,那么集合视图方法甚至不会被调用。

增加了IB的限制但仍无效。 在下面,您可以看到示例视图控制器

导入UIKit     导入AVFoundation

let studentName = ["Stockholm","London","Paris","Oslo"]


class TableViewController: UITableViewController,UICollectionViewDelegate,UICollectionViewDataSource {


    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.estimatedRowHeight = 140

        tableView.rowHeight = UITableViewAutomaticDimension


        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    /*
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
     return 300
     }*/


    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return studentName.count
        //  return 0
    }


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! TableViewCell



        cell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, forRow: indexPath.row)


        cell.secondName.text = "Second Name is Here"
        cell.firstName.text = studentName[indexPath.row]
        print("cell height is == \(cell.frame.size.height)")
        // Configure the cell...

        return cell
    }

    // All collection view methods
    @available(iOS 6.0, *)


    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewReuseIdentifier", for: indexPath as IndexPath) as! myCollectionViewCell
        cell.collection_first.text = "1"

        cell.Collection_second.text = "2"
        print("in collection view number of items in section---cell--\(indexPath.row)--")
        return cell

    }

    @available(iOS 6.0, *)


    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        print("in collection view number of items in section---\(studentName.count)")
        return studentName.count
    }


    /*
     func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {

     return  2

     }
     //
     //    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
     //
     //        return 5
     //    }

     func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewReuseIdentifier", for: indexPath as IndexPath) as! myCollectionViewCell

     //.......cell configure....

     return cell

     }


     func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

     print("get selected collectionview itemindex \(indexPath.row)")

     }
     */


    //}
    /*
     // Override to support conditional editing of the table view.
     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
     // Return false if you do not want the specified item to be editable.
     return true
     }
     */

    /*
     // Override to support editing the table view.
     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
     if editingStyle == .delete {
     // Delete the row from the data source
     tableView.deleteRows(at: [indexPath], with: .fade)
     } else if editingStyle == .insert {
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
     }
     }
     */

    /*
     // Override to support rearranging the table view.
     override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

     }
     */

    /*
     // Override to support conditional rearranging of the table view.
     override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
     // Return false if you do not want the item to be re-orderable.
     return true
     }
     */

    /*
     // MARK: - Navigation

     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */

}

0 个答案:

没有答案