2016-04-28 4 views
0

にリセットされます設定:スウィフト - プログラムが選択されたときに、私は、プログラムのUITableViewCellのレイアウトを設定していますUITableViewCellのスクロール

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    self.selectedCellIndexPath = indexPath 
    var selectedCell = tableView.cellForRowAtIndexPath(indexPath)! 
    tableView.beginUpdates() 
    tableView.endUpdates() 
    var cell:SelectedPatientCell = tableView.dequeueReusableCellWithIdentifier("patient selected", forIndexPath: indexPath) as! SelectedPatientCell 
    cell.patientName.text = patients[indexPath.row].fullName 
    cell.dob.text = patients[indexPath.row].dob 
    ... 
    selectedCell = cell 
} 

そして、私はその元のレイアウトセットにのtableView、セルのリセットのレイアウトをスクロールcellForRowAtIndexPath内にあります。しかし、高さは上記の関数で設定したときと同じです。誰もがこれを修正する方法を知っていますか?ここで

は何が起こっているかのアルバムである: http://imgur.com/a/OUIMJ

画像1:元の状態

画像2:選択された状態(それがスクロールにとどまるべきか)

画像3:何が実際に起こります

+0

を解決問題が何であるか明確ではない。あなたが達成しようとしていることと間違っていることについてもっと説明できますか?選択したセルを変更しようとしていますか? – ocwang

+0

であるため、セルには未選択と選択の2つの状態があります。それが選択され、私がスクロールすると、元のレイアウトにリセットされます。私はそれをより明確にするためにいくつかのスクリーンショットを取ることができるかどうかを知るでしょう。 – nerras

答えて

0

だから私は私自身の解決策が見つかりました:私は、関数の最後にこれを行うために必要な 代わりの

tableView.beginUpdates() 
    tableView.endUpdates() 

をやった:

tableView.reloadData() 

、それはそれだ問題

1

あなたは

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

    if indexPath == self.selectedCellIndexPath { 
     var cell:SelectedPatientCell = tableView.dequeueReusableCellWithIdentifier("patient selected", forIndexPath: indexPath) as! SelectedPatientCell 
     cell.patientName.text = patients[indexPath.row].fullName 
     cell.dob.text = patients[indexPath.row].dob 
     return cell 
    } 
    let cell = tableView.dequeueReusableCellWithIdentifier("patient selected") as! OriCell 
    ... 
    return cell 
} 
で、この状態を保持する必要があります

このようにしてtableViewをスクロールすると、元のCellに再開されません。 うまくいけば分かります。

+0

サンプルモデルを使用しているユーザーの詳細を説明してください。後で質問に来るすべての人に役立ちます。 – Shubhank

+0

私の答えがリセットされました。それを選択してください – xiaoming

+0

このソリューションは私のためには機能しません – nerras

関連する問題