Я могу успешно передать строку сообщение между двумя классами, но мой UIAlertAction
не отображает сообщение.UIAlertAction не отображает переданное сообщение
Код отправки сообщения
var message = String()
Alamofire.request(.POST, endPoint, headers: Auth_header, parameters: parameters, encoding: .JSON)
.validate()
.responseJSON {
response in
switch response.result {
case .Success(let data):
let value = JSON(data)
if value["message"].string != nil {
message = String(value["message"])
let dic = ["message": message]
print("hello")
NSNotificationCenter.defaultCenter().postNotificationName("notification",object: nil, userInfo: dic)
}
onCompletion()
case .Failure(let error):
print("Request failed with error: \(error)")
onError?(error)
}
Код приема и отображения сообщения
import UIKit
class TaskDetailsViewController: UIViewController {
@IBAction func submitBtn(sender: AnyObject) {
loadTasks()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TaskDetailsViewController.displayMessage(_:)), name: "notification", object: nil)
}
func displayMessage(notification: NSNotification) {
if let message = notification.userInfo!["message"]{
//initialize Alert Controller
let alertController = UIAlertController(title: "Success", message: message.string, preferredStyle: .Alert)
print(message)
print("world")
//Initialize Actions
let okAction = UIAlertAction(title: "Ok", style: .Default){
(action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}
//Add Actions
alertController.addAction(okAction)
//Present Alert Controller
self.presentViewController(alertController, animated: true, completion: nil)
}
}
Мой распечатывают
hello
Score created.
world
что вы имеете в виду? Не проблема в методе, отображающем предупреждение, поскольку сообщение может быть передано просто отлично – noobdev