tableview swift 3中的不同单元格

时间:2017-07-03 06:36:47

标签: ios swift xcode uitableview

示例[1]:https://i.stack.imgur.com/8cORc.png

  1. 如何正确制作下表 我不想拐杖 所有单元格一个接一个,除了一个X.count块,会有不同的数字(来自两个或更多)

  2. 如何稍后从块X中找出第一个和最后一个单元格以显示或隐藏单元格之间的条带(在点之间,我制作它们的三个单元格,并希望隐藏或显示单元格取决于细胞)

  3. import UIKit
    import CoreLocation
    import Alamofire
    import SwiftyJSON
    
    
    class TableVC: UIViewController,UITableViewDelegate, UITableViewDataSource {
    
        @IBOutlet weak var tableView: UITableView!
    
        @IBOutlet weak var loadingView: UIView!
    
    
        var number: String! = "number"
    
        var detail_data: DetailListData?
    
    
    
    
    
    
    
        var token: String?
        var json = "Invalid"
    
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
    
            loadingView.isHidden = false
    
            print("===============================",number!)
    
            tableView.register(UINib(nibName: "HeaderTVC", bundle: Bundle.main), forCellReuseIdentifier: "HeaderTVC")
            tableView.register(UINib(nibName: "DistanceTVC", bundle: Bundle.main), forCellReuseIdentifier: "DistanceTVC")
            tableView.register(UINib(nibName: "MapTVC", bundle: Bundle.main), forCellReuseIdentifier: "MapTVC")
            tableView.register(UINib(nibName: "InfoTVC", bundle: Bundle.main), forCellReuseIdentifier: "InfoTVC")
            tableView.register(UINib(nibName: "BottomTVC", bundle: Bundle.main), forCellReuseIdentifier: "BottomTVC")
    
            tableView.delegate = self
    
            token = UserDefaults.standard.value(forKey: "token")! as? String
    
            getData()
        }
    
        func getData () {
    
            let httpHeaders = ["Authorization": token!,
                               "Accept": "application/json"]
    
            Alamofire.request(REST_API.MAIN_URL_DEV + REST_API.SHIPMENTS + "/" + number! ,encoding: JSONEncoding.default, headers: httpHeaders)
                .responseString { response in
    
                    if let JSON = response.result.value {
                        self.json = JSON
    
                        //                    print(JSON)
    
                        if let jsonObj = self.json.parseJSONString {
    
                            if let data = jsonObj as? NSDictionary {
    
                                if let obj = DetailListJson4Swift_Base(dictionary: data) {
    
    
                                    if obj.status?.code == 200 {
    
                                        self.detail_data = obj.data
    
    
                                        print("////====================  DATA", obj.data!, self.detail_data!)
    
    
                                        self.loadingView.isHidden = true
    
                                        self.tableView.reloadData()
    
    
                                    } else {
    
                                        print("Status: Error code")
                                        MyAlertController.doAlert("Error", alertMessage: "something wrong, try again late")
                                    }
    
                                } else {
                                    MyAlertController.doAlert("Error", alertMessage: "Unable to construct movie object")
                                    print("Unable to construct movie object")
                                }
    
                            } else {
                                MyAlertController.doAlert("Error", alertMessage: "Unable to interpret parsed object as dictionary")
                                print("Unable to interpret parsed object as dictionary")
                                print(jsonObj)
                            }
                        }
                    }
            }
        }
    
        @IBAction func accept(_ sender: Any) {
    
    
        }
    }
    
    
    extension TableVC {
    
    
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
            if detail_data != nil {
    
                if section == 0 {
    
                    return 3
    
                } else if section == 1 {
    
    
                    return (detail_data?.waypoints?.count)!
                } else if section == 2 {
    
    
                    return 1
                }
    
            }
            return 0
        }
    
        func numberOfSections(in tableView: UITableView) -> Int {
    
            return 2
        }
    
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    
            if indexPath.row == 0 {
    
                let headerTVC = tableView.dequeueReusableCell(withIdentifier: "HeaderTVC", for: indexPath) as! HeaderTVC
    
                headerTVC.code.text = detail_data?.id!
                headerTVC.price.text = detail_data?.price?.total!
                headerTVC.distamce.text = detail_data?.distance!
                return headerTVC
    
            }
    
    
            if indexPath.row == 1 {
    
                let distanceTVC = tableView.dequeueReusableCell(withIdentifier: "DistanceTVC", for: indexPath) as! DistanceTVC
    
    
    
                return distanceTVC
            }
    
            if indexPath.row == 2 {
    
                let mapTVC = tableView.dequeueReusableCell(withIdentifier: "MapTVC", for: indexPath) as! MapTVC
    
    
                return mapTVC
            }
    
            if indexPath.row == 4 {
    
                let bottomTVC = tableView.dequeueReusableCell(withIdentifier: "BottomTVC", for: indexPath) as! BottomTVC
    
    
    
                return bottomTVC
            }
    
    
    
            // the other cells should contains title and subtitle:
            let infoTVC = tableView.dequeueReusableCell(withIdentifier: "InfoTVC", for: indexPath) as! InfoTVC
    
    
            return infoTVC
        }
    
        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            return UITableViewAutomaticDimension
        }
    
        func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            return UITableViewAutomaticDimension
        }
    

0 个答案:

没有答案