簡體   English   中英

如何快速在索引路徑委托的行中的單元格中加載自定義表格視圖單元格

[英]How to load a custom table view cell in cell for row at indexpath delegate in swift

import UIKit

class NewOrdersViewControllers: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var items = []
    @IBOutlet var tableView:UITableView!

    @IBOutlet weak var lblRestaurantNames: UILabel!
    @IBOutlet weak var mapView: UIButton!

    var cellIdentifier = "cell"


    override func viewDidLoad() {
        super.viewDidLoad()

        //self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
        let nib = UINib(nibName: "vwTblCell", bundle: nil)

        tableView.registerNib(nib, forCellReuseIdentifier: "cell")
        tableView.delegate = self

        tableView.dataSource = self

        // Do any additional setup after loading the view.
    }

    @IBAction func mapPush(sender: AnyObject) {

        let mapVC = MapViewController()

        self.navigationController?.pushViewController(mapVC, animated: true)
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.items.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

//            let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier(cellIdentifier)! as! UITableViewCell
//
//            cell.textLabel?.text = self.items[indexPath.row] as! String
//
//            cell.RestaurantLbl.text = self.items[indexPath.row]
//
//            cell.lblrest.text = items[indexPath.row] as! String

        var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell

        cell.lblRestaurantName.text = items[indexPath.row] as! String

        return cell
    }

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

        print("You selected cell #\(indexPath.row)!")
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

        return 100
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

        let identifier = "Custom"

        var cell: CustomCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCel  

          if cell == nil {
                tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: identifier)
               cell =tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCell
            }
          return cell
        }
   func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
         let cell:TblCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TblCell

         cell.lblRestaurantName.text = items[indexPath.row] as! String

        return cell;

   }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM