2016-04-02 5 views
0

私は下のテーブルビューの上に検索バーがあるViewControllerを持っています。テーブルビューには、2つのラベルがあるカスタムセルがあります。私の問題は、私がアプリを実行し、私は行/セルを選択すると、セル内のすべてが消えてしまうことです。私はそれから、空白のセルをテーブルビューの可視領域の外に置いて再利用します。それが細胞内のすべてが戻ってくる時です。それがなぜこのように振る舞うのか誰にも分かりますか?テーブルビューの行を選択して、カスタムセルを削除します。

マイカスタムセルクラス(ContactCell.swift):

import UIKit 

class ContactCell: UITableViewCell { 

    @IBOutlet var lblContactName: UILabel! 
    @IBOutlet var lblContactTitle: 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 
    } 
} 

私のviewDidLoad機能:

override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.dataSource = self 
    tableView.delegate = self 
} 

私の代理人とデータソース:

extension contactsTabelViewController: UITableViewDelegate, UITableViewDataSource { 

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("contactCell", forIndexPath: indexPath) as! ContactCell 

     if let label = cell.lblContactName{ 
      label.text = "This is a name" 
     } 
     if let label3 = cell.lblContactTitle{ 
      label3.text = "This is a title" 
     } 

     return ContactCell() 
    } 
} 

答えて

0

この問題の原因となった問題私は変数cellの代わりにContactCell()を返しました

ソリューションでした。これを変更 :cellForRowAtIndexPath機能で

return cell 

:これまで

return ContactCell() 

関連する問題