gpt4 book ai didi

ios - UITableViewCell在编辑模式下按减号后消失

转载 作者:行者123 更新时间:2023-11-30 13:01:00 24 4
gpt4 key购买 nike

我有一个自定义 TableViewCell,其中包含一些标签、 slider 和播放按钮。如果没有音频文件,则单元格不可展开,并且 slider 和播放按钮不可见。但是,当有音频时,单元格会扩展以显示所有内容。

如果我进入编辑模式并按减号,它会按预期工作。

现在来解决这个问题。单元格滑过以显示删除按钮。如果我扩展和收缩单元格,然后按减号,它就会飞出屏幕。这是一个 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)
}

我猜这与调整大小有关。如果需要,我可以发布更多代码。谢谢

最佳答案

我所要做的就是注释掉这一行:

cell.autoresizingMask = UIViewAutoresizing.FlexibleHeight

关于ios - UITableViewCell在编辑模式下按减号后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39906163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com