选定时间的 iPhone 闹钟
我在创建闹钟应用程序时遇到问题。 我拥有的只是日期选择器、标签、按钮。
@interface app6ViewController : UIViewController {
UILabel *dateLabel;
UIDatePicker *datePicker;
NSDate *alarm;
}
-(IBAction)getSelection;
-(IBAction)checkAlarm;
@property(nonatomic,retain) IBOutlet UILabel *dateLabel;
@property(nonatomic,retain) IBOutlet UIDatePicker *datePicker;
@end
在 .m 文件中
-(void)getSelection
{
//from date picker good part
NSLocale *usLocale = [[[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"] autorelease];
NSDate *pickerDate = [datePicker date];
NSString *selectionString = [[NSString alloc] initWithFormat:@"%@",
[pickerDate descriptionWithLocale:usLocale]];
dateLabel.text = selectionString;
[selectionString release];
alarm = pickerDate;
//[mylabel setText:(@"text")]; //this string works
NSTimer *checkAlarm = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(checkAlarm:) userInfo:nil repeats:YES];
}
-(void)checkAlarm:(NSTimer *)t{
if ([NSDate date] == alarm){
// Alarm reached
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Alarm"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release] ;
[t invalidate];
}
}
,但它不会触发警报:( 我不明白为什么。
I am having trouble creating alarm app.
all I have is Datepicker, label, button.
@interface app6ViewController : UIViewController {
UILabel *dateLabel;
UIDatePicker *datePicker;
NSDate *alarm;
}
-(IBAction)getSelection;
-(IBAction)checkAlarm;
@property(nonatomic,retain) IBOutlet UILabel *dateLabel;
@property(nonatomic,retain) IBOutlet UIDatePicker *datePicker;
@end
and in .m file
-(void)getSelection
{
//from date picker good part
NSLocale *usLocale = [[[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"] autorelease];
NSDate *pickerDate = [datePicker date];
NSString *selectionString = [[NSString alloc] initWithFormat:@"%@",
[pickerDate descriptionWithLocale:usLocale]];
dateLabel.text = selectionString;
[selectionString release];
alarm = pickerDate;
//[mylabel setText:(@"text")]; //this string works
NSTimer *checkAlarm = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(checkAlarm:) userInfo:nil repeats:YES];
}
-(void)checkAlarm:(NSTimer *)t{
if ([NSDate date] == alarm){
// Alarm reached
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Alarm"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release] ;
[t invalidate];
}
}
but I it doesnt triggers alarm :( I cant figure out why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用断点检查你的警报方法是否被调用?
尝试这样...一些东西
check with breakpoint whether your alarm method is called ??
try like this ...something