2015-03-03 3 views
0

AppDelegate:функции делегата UIAlertView не вызывается

func application(application: UIApplication, didReceiveRemoteNotification userInfo: NSDictionary) { 
    let aps: NSDictionary = userInfo.objectForKey("aps") as NSDictionary 
    UpdatesViewController().newArticle(aps) 
} 

UpdatesViewController:

class UpdatesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate { 
    func newArticle(userInfo: NSDictionary) { 
     let title: NSString = userInfo["alert"] as NSString 
     UIAlertView(title: "New update", message: title, delegate: self, cancelButtonTitle: "Dismiss", otherButtonTitles: "Read more").show() 
    } 

    func alertView(alertView: UIAlertView, willDismissWithButtonIndex buttonIndex: Int) { 
     println(buttonIndex) 
    } 

    func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) { 
     println(buttonIndex) 
    } 
} 

Я получаю UIAlertView с правильным сообщением от APNS, когда толчок уведомление будет отправлено. Проблема в том, что при нажатии любой из двух кнопок в UIAlertView пресса не регистрируется через println.

Любые идеи?

+0

'UpdatesViewController()' создает новый экземпляр 'UpdatesViewController'. Это будет выпущено до того, как делегат будет вызван, потому что он не сохранился нигде. Вы пытаетесь вызвать функцию в существующем контроллере представления? – rakeshbs

+1

Лучше сказать «нет сильной ссылки». – zaph

ответ

1

с iOS8 UIAlertView Делегат устарел. Используйте вместо этого UIAlertViewController.

1

UIAlertView устарел. Используйте UIAlertController вместо preferredStyleUIAlertControllerStyleAlert.

// Пример кода дисплей предупреждение

let alertController = UIAlertController(title: "Default Style", message: "A standard alert.", preferredStyle: .Alert) 
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { enter code here } 
Смежные вопросы