UILocalNotification 未触发
我对 Cocoa Touch 和 Objective-C 非常陌生,但我已经掌握了相当重要的要点,并且正在尝试 UIKit。我有一个链接到按钮的操作,该按钮更改标签并触发 UILocalNotification,这就是操作方法:
- (IBAction)changeLabel:(id)sender {
self.LabelOne.text = @"WHAT UPPP!";
self.NotifyOne.alertBody = @"Testtttttt";
self.NotifyOne.alertAction = @"Got It.";
self.NotifyOne.fireDate = nil;
}
没有错误或警告,但它只是没有触发。难道是我的动作方法有问题?
更新
以下是包含 UILocalNotification 的应用程序委托初始化:
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *_NotifyOne;
}
@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;
I am very new to Cocoa Touch and Objective-C but I've gotten the pretty big points down and I am experimenting with the UIKit. I have a action linked to a button that changes a label and fires a UILocalNotification and this is the action method:
- (IBAction)changeLabel:(id)sender {
self.LabelOne.text = @"WHAT UPPP!";
self.NotifyOne.alertBody = @"Testtttttt";
self.NotifyOne.alertAction = @"Got It.";
self.NotifyOne.fireDate = nil;
}
There are no errors or warnings, but it's just not firing. Is there anything wrong with my action method?
UPDATE
Here is the App Delegate initialization that contains the UILocalNotification
:
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *_NotifyOne;
}
@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望它在没有时间表的情况下显示(例如,当您按下按钮时),请使用
UIAlertView
或将[application presentLocalNotificationNow:self.NotifyOne];
添加到您的代码中。更新
删除 IBOutlet 并使 UILocalNotification 的两个声明具有相同的名称。例如:
请记住在实现 (.m) 文件中
synthesize
。也可以试试这个:
If you are wanting it show without a schedule (eg. when you press a button) then either use
UIAlertView
or add[application presentLocalNotificationNow:self.NotifyOne];
to your code.UPDATE
Remove IBOutlet and make both declarations of UILocalNotification the same name. For example:
Remember to
synthesize
in your implementation (.m) file.Also try this instead:
你有安排闹钟吗?这是我用来发出警报的代码。
Are you ever scheduling the alarm? Here is code I use to fire alarms.
如果您不向
UILocalNotification
提供fireDate
并将其安排到您的应用程序实例,则UILocalNotification
不会触发。如果您尝试立即呈现某种警报,也许您应该尝试使用UIAlertView
。A
UILocalNotification
isn't going to fire if you don't provide it with afireDate
and schedule it with your application instance. If you're trying to immediately present some sort of alert, perhaps you should try usingUIAlertView
.