首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift 3协议和代理方法?

Swift 3协议和代理方法?
EN

Stack Overflow用户
提问于 2017-03-24 00:02:05
回答 1查看 3.5K关注 0票数 3

我环顾四周,阅读了大量的博客,找出了如何实现我的目标。我遇到的最容易理解的帖子就是这里的Pass data back to previous viewcontroller。我确信我的理解是混乱的,但当我在第二个视图中滑动一个单元格时,我想要完成的是从地图中删除一个注释。

从CoreData中删除注释不是问题,当我单击rightCallOut时移除引脚也不是问题。当我想从VC1中的VC2操作中删除映射中的注释时,问题就出现了。我在哪里误解这个简单的过程,以及如何完成它?

FirstViewController

代码语言:javascript
复制
import UIKit

class ViewController: UIViewController, PinRemoverDelegate {

    func removePin() {
        mapView.removeAnnotation(selectedAnnotation)
    }

}

SecondViewController

代码语言:javascript
复制
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()
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-24 02:17:51

误解只是如何取下别针。调用removePin函数是错误的。只需重新加载CoreData,因为引脚已经从CoreData中移除。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42989123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档