gpt4 book ai didi

iphone - UILocalNotification 未触发

转载 作者:行者123 更新时间:2023-12-03 19:31:09 25 4
gpt4 key购买 nike

我对 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 的应用程序委托(delegate)初始化:

@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *_NotifyOne;
}

@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;

最佳答案

如果您希望它在没有时间表的情况下显示(例如,当您按下按钮时),请使用 UIAlertView 或添加 [application presentLocalNotificationNow:self.NotifyOne];到您的代码。

更新

删除 IBOutlet 并使 UILocalNotification 的两个声明具有相同的名称。例如:

@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *NotifyOne;
}

@property (nonatomic, retain) UILocalNotification *NotifyOne;

请记住在您的实现 (.m) 文件中synthesize

也可以尝试这个:

- (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;
}
}

关于iphone - UILocalNotification 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com