2014-12-09 1 views
0

Swift에서 custom tableview 셀을 xib 파일로 가지고 있는데, 이는 괜찮습니다. 그리고 링크가있는 신속한 파일을 가지고 있습니다. 그래서 같은신속한 커스텀 UITableViewCell

:

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 파일이 있는데이 파일에는 tableview가 있습니다. 이 코드는 제가이 코드에 사용했지만 어떻게이 tableview (뷰 컨트롤러)에서 생성 한 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

세포 식별자가 다릅니다. 오식?

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 
    } 
관련 문제