我是Swift新手,我正在使用视频课程。但在目前的课程中,我有一个问题,我无法自己解决。Swift #selector issue
问题是在NSNotificationCenter中使用了新的#selector语法,我使用了旧的语法,但它不起作用。
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onPostsLoaded:", name: "postsLoaded", object: nil)
tableView.reloadData()
}
func onPostsLoaded(notif:AnyObject) {
tableView.reloadData()
}
}
请检查截图:How should I rewrite the yellow code (with selector) to make it work?
在此先感谢
这也是行之有效的。NSNotificationCenter.defaultCenter()的addObserver(自我,选择:#selector(self.onPostsLoaded(_ :)),名称: “postsLoaded”,对象:无) – Mannopson