nkc*_*cmr 3 iphone cocoa-touch ios4 uilocalnotification
我是很新的,以可可触摸和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;
}
Run Code Online (Sandbox Code Playgroud)
没有错误或警告,但它只是没有开火.我的行动方法有什么问题吗?
UPDATE
这是App Delegate初始化,包含UILocalNotification:
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *_NotifyOne;
}
@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;
Run Code Online (Sandbox Code Playgroud)
如果您希望它在没有时间表的情况下显示(例如按下按钮时),则使用UIAlertView或添加[application presentLocalNotificationNow:self.NotifyOne];到您的代码中.
UPDATE
删除IBOutlet并使UILocalNotification的两个声明都具有相同的名称.例如:
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
UIButton *_ModifyLabelButton;
UILabel *_LabelOne;
UILocalNotification *NotifyOne;
}
@property (nonatomic, retain) UILocalNotification *NotifyOne;
Run Code Online (Sandbox Code Playgroud)
请记住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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4813 次 |
| 最近记录: |