我对Cocoa和Objective非常陌生,但我已经得到了相当大的分数,我正在试验UIKit。我有一个操作链接到一个按钮,该按钮可以更改标签并触发一个UILocalNotification,这就是action方法:
- (IBAction)changeLabel:(id)sender {
self.LabelOne.text = @"WHAT UPPP!";
self.NotifyOne.alertBody = @"Testtttttt";
self.NotifyOne.alertAction = @"Got It.";
self.NotifyOne.fireDate = nil;
}没有错误或警告,但它只是没有触发。我的动作方法有什么问题吗?
更新
下面是包含UILocalNotification的App初始化
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *_NotifyOne;
}
@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;发布于 2011-08-08 21:53:09
如果你想要的话,就在没有时间表的情况下表演。当您按下一个按钮),然后使用UIAlertView或添加[application presentLocalNotificationNow:self.NotifyOne];到您的代码。
更新
删除IBOutlet并使UILocalNotification的两个声明都具有相同的名称。例如:
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *NotifyOne;
}
@property (nonatomic, retain) UILocalNotification *NotifyOne;请记住在您的实现( synthesize )文件中使用.m。
也可以尝试这样做:
- (IBAction)changeLabel:(id)sender {
self.LabelOne.text = @"WHAT UPPP!";
NotifyOne = [[UILocalNotification alloc] init];
if (NotifyOne) {
NotifyOne.alertBody = @"Testtttttt";
NotifyOne.alertAction = NSLocalizedString(@"Got It.", nil);
NotifyOne.fireDate = nil;
NotifyOne.soundName = nil;
NotifyOne.applicationIconBadgeNumber = 0;
[application presentLocalNotificationNow:NotifyOne];
[NotifyOne release];
NotifyOne = nil;
}
}发布于 2011-08-08 21:48:12
你安排过警报吗?这是我用来报警的代码。
UILocalNotification *alarm = [[UILocalNotification alloc] init];
if (alarm) {
alarm.fireDate = [NSDate date];
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.soundName = @"alarmsound.caf";
alarm.alertBody = @"Test message...";
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
[alarm release];
}发布于 2011-08-08 21:49:18
如果不为UILocalNotification提供fireDate并将其与应用程序实例一起调度,则不会触发它。如果您试图立即提出某种警告,也许您应该尝试使用UIAlertView。
https://stackoverflow.com/questions/6988986
复制相似问题