Swift
- 11 ответов
- 0 вопросов
10
Вклад в тег
class NextViewController: UIViewController {
var name: String!
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dest = segue.destination as? NextViewController {
dest.name = "Jessica"
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dest = segue.destination as? NextViewController {
if segue.identifier == "action1" {
dest.name = "Jessica"
} else if segue.identifier == "action2" {
dest.name = "Jessica"
dest.sex = "female"
}
}
}
let dest = storyboard?.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController
let dest = NextViewController(nibName:"NextViewController", bundle: nil)
dest.name = "Jessica"
navigationController?.pushViewController(dest, animated: true)
dest.modalPresentationStyle = .fullScreen
dest.modalTransitionStyle = .coverVertical
present(dest, animated: true, completion: nil)
protocol NextViewControllerDelegate {
func callback(_ someString: String)
}
class NextViewController: UIViewController {
var name: String!
var delegate: NextViewControllerDelegate?
func someMethod() {
delegate?. callback("delegate callback")
}
}
//Тут контроллер из которого открываем CustomViewController, нам помимо name нужно теперь еще задать delegate=self
class HomeViewController: UIViewController, NextViewControllerDelegate {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dest = segue.destination as? NextViewController {
dest.name = "Jessica"
dest.delegate = self
}
}
//MARK: NextViewControllerDelegate
func callback(_ someString: String) {
print("got callback with string: \(someString)")
}
}
let kNotifNextViewControllerCallback = NSNotification.Name(rawValue: "kNotifNextViewControllerCallback")
class NextViewController: UIViewController {
var name: String!
func someMethod() {
NotificationCenter.default.post(name: kNotifNextViewControllerCallback, object: "notification text")
}
}
//Тут HomeViewController из которого открываем CustomViewController, мы в нем будем слушать kNotifNextViewControllerCallback в метод gotNotification
class HomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(gotNotification(notification:)), name: kNotifNextViewControllerCallback, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dest = segue.destination as? NextViewController {
dest.name = "Jessica"
}
}
//MARK: Notification observer
func gotNotification(notification: Notification) {
print("got notification with object: \(notification.object)")
}
}
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated