2015-11-12 3 views
-1

У меня есть следующий кодIOS 9 Местные Уведомления с помощью Swift 2

@IBAction func triggerNotif(sender: UIButton) { 
    let dateComp:NSDateComponents = NSDateComponents() 
    dateComp.year = 2015 
    dateComp.month = 11 
    dateComp.day = 12 
    dateComp.hour = 21 
    dateComp.minute = 30 
    dateComp.timeZone = NSTimeZone.systemTimeZone() 

    let calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! 
    let date:NSDate = calender.dateFromComponents(dateComp)! 

    let notification:UILocalNotification = UILocalNotification() 
    notification.alertBody = "body of notification" 
    notification.fireDate = date 
    notification.repeatInterval = NSCalendarUnit.Day 

    UIApplication.sharedApplication().scheduleLocalNotification(notification) 
} 

В принципе, я пытаюсь вызвать уведомление, которое повторяется каждый день, используя UIButton. Я сослался на многие другие вопросы на этом сайте, чтобы сформировать этот код, и он успешно работает.

Но когда я нажимаю кнопку, я столкнулся с этим:

2015-11-12 18:30:17.025 Application Name[95723:485982] -[Application_Name.SettingsViewController triggerNotifBtn:]: unrecognized selector sent to instance 0x7f9163727d70 
2015-11-12 18:30:17.035 Application Name[95723:485982] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Application_Name.SettingsViewController triggerNotifBtn:]: unrecognized selector sent to instance 0x7f9163727d70' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010d293f45 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x000000010efb7deb objc_exception_throw + 48 
    2 CoreFoundation      0x000000010d29c56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x000000010d1e9eea ___forwarding___ + 970 
    4 CoreFoundation      0x000000010d1e9a98 _CF_forwarding_prep_0 + 120 
    5 UIKit        0x000000010dab1e91 -[UIApplication sendAction:to:from:forEvent:] + 92 
    6 UIKit        0x000000010dc1d4d8 -[UIControl sendAction:to:forEvent:] + 67 
    7 UIKit        0x000000010dc1d7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311 
    8 UIKit        0x000000010dc1c8d4 -[UIControl touchesEnded:withEvent:] + 601 
    9 UIKit        0x000000010db1fed1 -[UIWindow _sendTouchesForEvent:] + 835 
    10 UIKit        0x000000010db20c06 -[UIWindow sendEvent:] + 865 
    11 UIKit        0x000000010dad02fa -[UIApplication sendEvent:] + 263 
    12 UIKit        0x000000010daaaabf _UIApplicationHandleEventQueue + 6844 
    13 CoreFoundation      0x000000010d1c0011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    14 CoreFoundation      0x000000010d1b5f3c __CFRunLoopDoSources0 + 556 
    15 CoreFoundation      0x000000010d1b53f3 __CFRunLoopRun + 867 
    16 CoreFoundation      0x000000010d1b4e08 CFRunLoopRunSpecific + 488 
    17 GraphicsServices     0x0000000111887ad2 GSEventRunModal + 161 
    18 UIKit        0x000000010dab030d UIApplicationMain + 171 
    19 Application Name       0x000000010d0a8b6d main + 109 
    20 libdyld.dylib      0x000000010fabf92d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

Что случилось?

+0

Вы * прочитали * сообщение об ошибке? По-видимому, существует разница между именем вашей функции (triggerNotif) и непризнанным селектором (triggerNotifBtn), что означает, что вы, вероятно, переименовали функцию без повторного подключения действия в построителе интерфейса. - Эта проблема не имеет ничего общего с локальными уведомлениями. –

+0

Кажется, что вы изначально назвали ibaction «triggerNotifBtn» и связали его в своем интерфейсе. Затем переименовали функцию в 'triggerNotif'. Вот почему вы получаете такой крах. Повторно подключите розетку, это исправит проблему. –

ответ

0

вы устанавливаете triggerNotifBtn как имя функции, но имя вашей функции является triggerNotif

Смежные вопросы