我有一个带有一些标签,滑块和播放按钮的自定义TableViewCell。如果没有音频文件,则单元格不可展开,并且滑块和播放按钮不可见。但是,当有音频时,单元格会扩展以显示所有内容。
如果我进入编辑模式并按下减号,它会按预期工作。
现在出现问题。单元格滑过以显示删除按钮。如果我展开和收缩单元格,然后按减号,它会从屏幕上飞出。这是一个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 :(得分:0)
我所要做的只是注释掉这一行:
cell.autoresizingMask = UIViewAutoresizing.FlexibleHeight