我环顾四周,阅读了大量的博客,找出了如何实现我的目标。我遇到的最容易理解的帖子就是这里的Pass data back to previous viewcontroller。我确信我的理解是混乱的,但当我在第二个视图中滑动一个单元格时,我想要完成的是从地图中删除一个注释。
从CoreData中删除注释不是问题,当我单击rightCallOut时移除引脚也不是问题。当我想从VC1中的VC2操作中删除映射中的注释时,问题就出现了。我在哪里误解这个简单的过程,以及如何完成它?
FirstViewController
import UIKit
class ViewController: UIViewController, PinRemoverDelegate {
func removePin() {
mapView.removeAnnotation(selectedAnnotation)
}
}SecondViewController
import UIKit
protocol PinRemoverDelegate: class {
func removePin()
}
class SecondViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
weak var delegate: PinRemoverDelegate? = nil
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let place = storedLocations[indexPath.row]
context.delete(place)
(UIApplication.shared.delegate as! AppDelegate).saveContext()
// Attempt To remove The Pin
delegate?.removePin()
}
tableView.reloadData()
}
}发布于 2017-03-24 02:17:51
误解只是如何取下别针。调用removePin函数是错误的。只需重新加载CoreData,因为引脚已经从CoreData中移除。
https://stackoverflow.com/questions/42989123
复制相似问题