2016-10-06 3 views
0

ラベル、スライダ、再生ボタンがあるカスタムTableViewCellがあります。オーディオファイルがない場合、セルは展開できず、スライダと再生ボタンは表示されません。ただし、オーディオがある場合は、セルが展開されてすべてが表示されます。編集モードでマイナスを押すとUITableViewCellが消える

編集モードに入り、マイナスを押すと、正常に機能します。

問題が発生しました。セルがスライドして削除ボタンが表示されます。セルを伸縮させてマイナスを押すと、画面から飛びます。ここではgifがありますので、私の言いたいことが分かります。

は、ここで私は、私はそれがサイズ変更とは何かを持って推測している

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! HistoryTBCell 
    cell.autoresizingMask = UIViewAutoresizing.FlexibleHeight 
    cell.clipsToBounds = true 
    tableView.beginUpdates() 

    if cell.isExpandable == true { 
     if toggle == 1 { 
      selectedRow = indexPath 
      toggle = 0 
     } else { 
      selectedRow = NSIndexPath(forRow: 1, inSection: 2) 
      toggle = 1 
     } 
    } 

    tableView.endUpdates() 
} 



override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if selectedRow == indexPath { 
     return 120 
    } else { 
     return 60 
    } 
} 

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle { 
    if self.tableView.editing { 
     return .Delete 
    } else { 
     return .None 
    } 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryTBCell 
    cell.selectionStyle = .None 
    cell.clipsToBounds = true 
    let hists = history[indexPath.row] 

    let date = hists.valueForKey("currentDate") as! String 
    let speechTime = hists.valueForKey("speechTime") as! String 
    let actualTime = hists.valueForKey("actualTime") as! String 
    let rec = hists.valueForKey("recURL") as! String 

    cell.configure(date: date, speech: "Speech Time: \(speechTime)", actual: "Actual Time: \(actualTime)") 

    if rec != "" { 
     cell.setUpAudio(url: rec) 
    } 

    return cell 
} 

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle == .Delete { 

     let alert = UIAlertController(title: "Delete", message: "Are you sure you want to delete?\nThe recording will also be deleted", preferredStyle: .ActionSheet) 

     alert.addAction(UIAlertAction(title: "Delete", style: .Default, handler: { void in 
      //let context = self.appDelegate?.managedObjectContext 
      let fileManager = NSFileManager.defaultManager() 
      let hists = self.history[indexPath.row] 
      let rec = hists.valueForKey("recURL") as! String 
      self.getContext().deleteObject(self.history[indexPath.row]) 
      self.history.removeAtIndex(indexPath.row) 
      do { 
       try self.getContext().save() 
      } catch { 
       print("Could not save") 
      } 
      tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
      do { 
       let appended = rec 
       let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] 
       let pathurl = documentsDirectory.URLByAppendingPathComponent(appended) 
       try fileManager.removeItemAtPath(pathurl.path!) 
      } catch { 
       print("Could not remove item") 
      } 

     })) 

     alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)) 

     presentViewController(alert, animated: true, completion: nil) 
    } 
} 

override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) { 
    selectedRow = NSIndexPath(forRow: 1, inSection: 2) 
} 

を実装し、いくつかの方法があります。必要に応じてさらにコードを投稿することができます。おかげ

+0

あなたはaccessoryButtonTapped ...デリゲートメソッド内で取得した行を削除する前にselectedRowをリセットしようとしたことがありますか?テーブルビューの再読み込みによって、どのセルが新しいselectedRowになるのだろうか? – creeperspeak

+0

'cellForRowAtIndexPath:'のコードも追加してください。 – Adeel

+0

@creeperspeakデリゲートメソッドで行うことは何も変わっていないようです。 – nighttalker

答えて

0

は私がしなければならなかったすべては、この行をコメントアウトした

cell.autoresizingMask = UIViewAutoresizing.FlexibleHeight 
関連する問題