2016-04-25 10 views
0

テーブルをスクロールすると、ラグが表示されます。写真、またはデータベースの長いテキストは表示されません。追加情報が必要な場合は申し訳ありませんが、私の悪い英語スクロール時のテーブルビューの遅れ

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell = tableView.dequeueReusableCellWithIdentifier("audioCell", forIndexPath: indexPath) as? AudiosTableViewCell 

    if cell == nil { 
     cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "audioCell") as? AudiosTableViewCell 
    } else { 
     let realm = try! Realm() 
     let audios = realm.objects(Music)[indexPath.row] 
     let duration = audios.duration 
     var durationString = "" 

     if duration/60 < 10 { 
      durationString = durationString + "0" } 
     durationString = durationString + String(duration/60) + ":" 
     if duration%60 < 10 { 
      durationString = durationString + "0" } 
     durationString = durationString + String(duration%60) 

     cell!.artistLabel.text = audios.artist 
     cell!.titleLabel.text = audios.title 
     cell!.durationLabel.text = durationString 
    } 
    return cell! 
} 

のために、あなたが必要な正確に何を書いてください。私は多くの情報を見直し、多くの方法を試しました。私は苦しんでいます。それはうまくいきません。

答えて

2

この

let realm = try! Realm() 

がvideoDidLoadまたは同様に行われますが、私は

if audios.count == 0 { 
     let realm = try! Realm() 
     let audios = realm.objects(Music)[indexPath.row] 
} 

を示唆して一度だけ、その後

let realm = try! Realm() 
    let audiosStore = realm.objects(Music) 

を交換する必要があります

let audios = audiosStore[indexPath.row] 

あなたはあなたがレルムからすべてのオブジェクトごとの時間を求めている

let realm = try! Realm() 

を呼び出すとき。

+0

はどうもありがとうございました、私はあなたに+1の評判を置くだろうが、それは私ができないことです –

0

このコードをcellForRowの外に移動し、cellForRowトリガーの前に必ず呼び出してください。

let realm = try! Realm() 
0

tableView.dequeueReusableCellWithIdentifier("audioCell", forIndexPath: indexPath)nilを返すことはありません。あなたが既に知っている場合は次のようにコードを書き換えることができAudiosTableViewCellセルは、クラスを持っています:

// Make realm property of your view controller 
    let realm: Realm! 

// In viewDidLoad 
    realm = try! Realm() 


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

    let audios = realm.objects(Music)[indexPath.row] 
    let duration = audios.duration 
    var durationString = "" 

    if duration/60 < 10 { 
     durationString = durationString + "0" } 
    durationString = durationString + String(duration/60) + ":" 
    if duration%60 < 10 { 
     durationString = durationString + "0" } 
    durationString = durationString + String(duration%60) 

    cell.artistLabel.text = audios.artist 
    cell.titleLabel.text = audios.title 
    cell.durationLabel.text = durationString 
    return cell 
} 
関連する問題