2014-12-09 5 views
0

У меня есть пользовательская ячейка таблицы в Swift как файл xib, и это нормально, и у меня есть быстрый файл, который ссылается на него.Пользовательский UITableViewCell в swift

так:

import UIKit 

class CustomTableViewCell: UITableViewCell { 

    @IBOutlet weak var CellTitle: UILabel! 
    @IBOutlet weak var CellLocation: UILabel! 
    @IBOutlet weak var CellDate: UILabel! 
    @IBOutlet weak var Type: UIImageView! 
    @IBOutlet weak var TypeText: UILabel! 



    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 

} 

в IBOutlets только ссылки на UILabels и UIImageViews, но они не нуждаются в каких-либо значений в данный момент, потому что они добавляют в дизайн на данный момент.

У меня есть файл ViewController, который связан с контроллером вида на раскадровке, и на нем есть табличное представление. , и это код, который я использовал для этого, но как я могу использовать customCell, который я создал на этом столе (контроллер просмотра).

import UIKit 

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

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

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 0 
    } 

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

     let cell = tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath) as UITableViewCell 


     return cell 
    } 

}

Любая помощь будет блестящим, благодаря

Я добавил:

var nib = UINib(nibName: "CustomTableViewCell", bundle: nil) 
     tableView.registerNib(nib, forCellReuseIdentifier: "customCell") 

зарегистрировать острия имя и зарегистрировать ячейку в Tableview, и у меня есть также изменил cellforindexpath на:

var cell:CustomTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("CustomCell") as CustomTableViewCell 
+0

Я добавил: hhhh – Jason

+0

Какой erorr выполняет эта настройка? –

ответ

1

cellIdentifier - другой. опечатка?

tableView.registerNib(nib, forCellReuseIdentifier: "customCell") 

var cell:CustomTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("CustomCell") as CustomTableViewCell 
0

попробуйте это !!

override func viewDidLoad() { 
      super.viewDidLoad() 
    self.tableView.delegate = self 
    self.tableView.datasourse = self 
    self.tableView.registerNib(nib, forCellReuseIdentifier: "customCell") 
     } 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 0 
    } 

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

     let cell = tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath) as UITableViewCell 


     return cell 
    } 
Смежные вопросы