当选定的时间(通过DatePicker)在iPhone中发生时,如何创建事件?

当选定的时间(通过DatePicker)在iPhone中发生时,如何创建事件?,iphone,objective-c,event-handling,datepicker,alarm,Iphone,Objective C,Event Handling,Datepicker,Alarm,我想做一个定制的闹钟。所以我选择了约会选择者。现在我想通过Datepicker在选定的时间发生时播放一个声音 那么,有谁能告诉我应该使用哪些类或API,或者有什么方向吗?如何使所选时间与创建事件的系统时间相匹配。我知道如何演奏声音。其他事情对我来说是个大问号。任何帮助都是值得的 到目前为止,我已经编写了这段代码,它只是显示一个日期选择器,点击按钮,它会显示所选的时间P 代码:- **.h File** #import <UIKit/UIKit.h> @interface The4

我想做一个定制的闹钟。所以我选择了约会选择者。现在我想通过Datepicker在选定的时间发生时播放一个声音

那么,有谁能告诉我应该使用哪些类或API,或者有什么方向吗?如何使所选时间与创建事件的系统时间相匹配。我知道如何演奏声音。其他事情对我来说是个大问号。任何帮助都是值得的

到目前为止,我已经编写了这段代码,它只是显示一个日期选择器,点击按钮,它会显示所选的时间P

代码:-

**.h File**

#import <UIKit/UIKit.h>

@interface The420DudeViewController : UIViewController {

    IBOutlet UINavigationBar *titleBar;
    IBOutlet UIButton *setAlarmButton;
    IBOutlet UIDatePicker *selectTimePicker;

}

@property(nonatomic, retain) IBOutlet UINavigationBar *titleBar;
@property(nonatomic, retain) IBOutlet UIButton *setAlarmButton;
@property(nonatomic, retain) IBOutlet UIDatePicker *selectTimePicker;

-(IBAction)onTapSetAlarm;

@end



**.m file **

@implementation The420DudeViewController

@synthesize titleBar,setAlarmButton,selectTimePicker;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

-(IBAction)onTapSetAlarm
{

    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm a"];

    NSDate *selectedDate = [[NSDate alloc] init];
    selectedDate = [selectTimePicker date];

    NSString *theTime = [timeFormat stringFromDate:selectedDate];

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Time selected" message:theTime delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:nil];

    [alert show];
    [alert release];
//  [timeFormat release];
//  [selectedDate release];


}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
    [titleBar release];
    [setAlarmButton release];
    [selectTimePicker release];
}

@end
**.h文件**
#进口
@与ViewController的接口:UIViewController{
IBUINAVIGATIONBAR*标题栏;
IBUIButton*设置报警按钮;
IBUIDatePicker*选择TimePicker;
}
@不动产(非原子,保留)IBUINAVIGATIONBAR*标题栏;
@属性(非原子,保留)IBUIButton*setAlarmButton;
@属性(非原子,保留)IBUIDatePicker*selectTimePicker;
-(IBAction)onTapSetAlarm;
@结束
**.m文件**
@视图控制器的实现
@合成标题栏,设置报警按钮,选择时间选择器;
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
[超级视图下载];
}
-(IBAction)onTapSetAlarm
{
NSDateFormatter*timeFormat=[[NSDateFormatter alloc]init];
[时间格式setDateFormat:@“HH:mm a”];
NSDate*selectedDate=[[NSDate alloc]init];
selectedDate=[selectTimePicker日期];
NSString*时间=[timeFormat stringFromDate:selectedDate];
UIAlertView*警报=[[UIAlertView alloc]
initWithTitle:@“Time selected”消息:时间委托:nil CancelButtonTile:@“YES”其他按钮:nil];
[警报显示];
[警报发布];
//[时间表发布];
//[选择日期释放];
}
-(无效)未收到记忆警告{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
-(无效)视图卸载{
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(无效)解除锁定{
[super dealoc];
[标题栏释放];
[设置报警按钮释放];
[选择时间选择器释放];
}
@结束

您应该查看
UILocalNotification
类-这将允许您的警报在应用程序关闭/处于后台时发出:


只需将本地通知的
fireDate
设置为
[selectTimePicker date]
,然后安排它

谢谢你的回复。。。我现在检查一下,然后试试。。。希望它能让我的一天。。。我很乐意接受这个答案。:)如果有人有类似的东西,请给我一个链接任何教程。。。赵