I have followed this tutorial
http://ios.biomsoft.com/2011/08/27/iphone-programming-tutorial-–-local-notifications/
I am able to run the app, however in order to run the app I have remove the following code in my appdelegate.m
You can see the error in the picture above.
Why do I receive the error and how do I fix the error?
Here is my code.
.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> {
IBOutlet UITableView *tableview;
IBOutlet UIDatePicker *datePicker;
IBOutlet UITextField *eventText;
}
#property (nonatomic, retain) IBOutlet UITableView *tableview;
#property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
#property (nonatomic, retain) IBOutlet UITextField *eventText;
- (IBAction) scheduleAlarm:(id) sender;
#end
.m
#implementation ViewController
#synthesize datePicker,tableview, eventText;
- (IBAction) scheduleAlarm:(id) sender {
[eventText resignFirstResponder];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit |
NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit |
NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = #"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:#"someValue"
forKey:#"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[self.tableview reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
datePicker = nil;
tableview = nil;
eventText = nil;
}
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// We only have one section
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of notifications
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
// Get list of local notifications
NSArray *notificationArray = [[UIApplication sharedApplication]
scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
// Display notification info
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];
return cell;
}
#end
You have to create an instance of the viewControllerfirst:
ViewController *viewController = [[ViewController alloc] init];
// set the frame, do other stuff..
[_window addSubview:viewController.view];
please check your AppDelegate code first
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
/******
YOUR CODE HERE
******/
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Ok so after doing some playing around. I was able to get the app to run without having to change the app delegate at all.
Not sure why in the tutorial he states to do so.
Thanks for you help.
Related
IPhone: I am doing my remainder app in Iphone,While i navigate from my "create new"-view to "edit"-View, I need my DatePicker to display the Value i have stored already when i just created the remainder, HENCE I need the DatePicker to return the time/date i specified when it is in edit view -Pls Help
1.My RemainderSetUpViewcontroller.h
`
#protocol RemainderDelegate <NSObject>
-(void)store:(NSArray *) remainderDel:(NSArray *) TimeDateDel;
#end
#interface RemainderSetUpViewcontroller : UIViewController<UITextFieldDelegate,UITextFieldDelegate>
{
UITextField *textField1;
NSString *str;
UIDatePicker *datePicker;
NSDate *date;
NSMutableArray *remainder;
NSMutableArray *TimeDate;
UILocalNotification* notification;
}
#property (strong, nonatomic)IBOutlet NSString* remainderr;
#property (strong, nonatomic)IBOutlet NSString *index;
#property(strong, nonatomic) id <RemainderDelegate> delegate;
-(void)addRemainder;
-(void)actionDone;
#end
`
2My RemainderSetUpViewcontroller.m:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
UIBarButtonItem *add = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(addRemainder)];
self.navigationItem.rightBarButtonItem=add;
//TextField1...............................................................................................................
self.title=#"Add Remainder";
textField1 = [[UITextField alloc]initWithFrame:CGRectMake(20, 60, 280, 34)];
textField1.borderStyle = UITextBorderStyleRoundedRect;
textField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField1.delegate = self;
textField1.placeholder = #"Enter the Reminder name";
[self.view addSubview:textField1];
//datePicker&TextField2....................................................................................................
datePicker=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,210, self.view.frame.size.width, self.view.frame.size.height)];
[datePicker addTarget:self action:#selector(actionDone) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
[[NSNotificationCenter defaultCenter] postNotificationName:#"reloadData" object:self];
//UserDefaults.............................................................................................................
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
remainder = [[NSMutableArray alloc]init];
TimeDate = [[NSMutableArray alloc]init];
if ([ud objectForKey:#"remainder"])
{
remainder = [[ud objectForKey:#"remainder"]mutableCopy];
TimeDate = [[ud objectForKey:#"TimeDate"]mutableCopy];
}
//to make the fields visible when we try to edit it............................................................................
if ([remainderr isEqualToString:#"edit"])
{
self.title = #"Reminder Edit";
textField1.text = [remainder objectAtIndex:[index integerValue]];
str = [TimeDate objectAtIndex:[index integerValue]];
}
}
#pragma mark - doneClicked
//DoneButton.................................................................................................................
-(void)actionDone
{
date = datePicker.date;
NSDateFormatter *dateform=[[NSDateFormatter alloc]init];
[datePicker setDate:[NSDate date]];
dateform.dateFormat = #"dd-MM-YYYY HH:mm:SS";
str=[dateform stringFromDate:date];
}
#pragma mark - AddRemainder Notifications
//addButton.................................................................................................................
-(void)addRemainder
{
//LocalNotification.........................................................................................................
notification = [[UILocalNotification alloc] init];
notification.fireDate = date;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
//NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([remainderr isEqualToString:#"edit"])
{
[remainder replaceObjectAtIndex:[index integerValue] withObject:textField1.text];
[TimeDate replaceObjectAtIndex:[index integerValue] withObject: str];
[self.navigationController popViewControllerAnimated:YES];
}
else if([remainderr isEqualToString:#"delete"])
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
else
{
if((textField1.text!=NULL)&&( date!=NULL))
{
[remainder addObject:textField1.text];
[TimeDate addObject: str];
[self.navigationController popViewControllerAnimated:YES];
}
else
{
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:#"Alert !" message:#"Please Give a title for your Remainder " delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[myAlert show];
}
}
//Adding objects............................................................................................................
//NSLog(#"%# %#", remainder, TimeDate);
[self.delegate store:remainder :TimeDate];
NSLog(#"The notifications is \n %#",notification);
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
#end
`
Thank you.
To display saved date in DatePicker, You need to set saved date in datepicker.
[datePicker setDate:savedDate animated:NO];
To display saved date in DatePicker, You need to set saved date in datepicker.
[datePicker setDate:savedDate animated:NO];
to get Date from datePicker
NSDate *date = datePicker.date;
Actually I am Making an Alarm app. In that When i set the Time The UILocalNotification event happens at that time and it calls the method of AppDelegate class i.e didReceiveNotifications method. In this method i have written a code to call a method of SetViewController (showReminder method) and now in this method i want that it should show a NewViewController i.e TimeViewController as i have to show animation when the Alarm Invokes.
I need this as When Alarm invokes i have setted a Action sheet to appear but i wanted to show animation also.Action sheet appears in all views But the animation can be Shown in only particular view, that's why i need to show A different ViewController.
Here is the code for what i am trying :-
I have tried al these also like PresentModalViewController, dismissModalViewController, AddSubview, remove superView... but result are negative :( what should i do..?
Almost Whole CODE:--
AppDelegate Class :-
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if (notification){
NSLog(#"In did Notification");
NSString *reminderText = [notification.userInfo objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
application.applicationIconBadgeNumber = 0;
}
}
setViewController.h :-
#interface SetAlarmViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate>{
IBOutlet UITableView *tableview;
IBOutlet UIDatePicker *datePicker;
IBOutlet UITextField *eventText;
TPKeyboardAvoidingScrollView *scrollView;
IBOutlet UINavigationBar *titleBar;
IBOutlet UIButton *setAlarmButton;
AVAudioPlayer *player;
int index;
The420DudeAppDelegate *appDelegate;
TimeViewController *viewController;
IBOutlet UIImageView *animatedImages;
NSMutableArray *imageArray;
AVPlayerItem *player1,*player3;
AVPlayerItem *player2,*player4;
AVQueuePlayer *queuePlayer;
}
#property (nonatomic, retain) IBOutlet UIImageView *animatedImages;
#property (nonatomic, retain) IBOutlet UITableView *tableview;
#property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
#property (nonatomic, retain) IBOutlet UITextField *eventText;
#property (nonatomic, retain) TPKeyboardAvoidingScrollView *scrollView;
#property(nonatomic, retain) IBOutlet UINavigationBar *titleBar;
#property(nonatomic, retain) IBOutlet UIButton *setAlarmButton;
#property(nonatomic) UIReturnKeyType returnKeyType;
#property(nonatomic, retain) IBOutlet TimeViewController *viewController;
- (IBAction) scheduleAlarm:(id)sender;
- (void)showReminder:(NSString *)text;
-(IBAction)onTapHome;
-(IBAction)onTapChange:(id)sender;
#end
SetViewController.m :-
#synthesize datePicker,tableview, eventText,titleBar,setAlarmButton,returnKeyType,scrollView,animatedImages,viewController;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (The420DudeAppDelegate *)[[UIApplication sharedApplication] delegate];
eventText.returnKeyType = UIReturnKeyDone;
viewController = [[TimeViewController alloc] initWithNibName:#"TimeViewController" bundle:nil];
NSDate *now = [NSDate date];
[datePicker setDate:now animated:YES];
eventText.delegate = self;
index = 0;
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"inhale" ofType:#"mp3"];
NSURL *url1 = [NSURL fileURLWithPath:path1];
player1 = [[AVPlayerItem alloc]initWithURL:url1];
NSString *path3 = [[NSBundle mainBundle] pathForResource:#"sound1" ofType:#"wav"];
NSURL *url3 = [NSURL fileURLWithPath:path3];
player3 = [[AVPlayerItem alloc]initWithURL:url3];
NSString *path2 = [[NSBundle mainBundle] pathForResource:#"exhale" ofType:#"mp3"];
NSURL *url2 = [NSURL fileURLWithPath:path2];
player2 = [[AVPlayerItem alloc]initWithURL:url2];
NSString *path4 = [[NSBundle mainBundle] pathForResource:#"Dude" ofType:#"mp3"];
NSURL *url4 = [NSURL fileURLWithPath:path4];
player4 = [[AVPlayerItem alloc]initWithURL:url4];
NSArray *items = [[NSArray alloc]initWithObjects:player1,player3,player2,player4,nil];
queuePlayer = [[AVQueuePlayer alloc] initWithItems:items];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playEnded) name:AVPlayerItemDidPlayToEndTimeNotification object:player4];
}
-(void)onAlarmInvoke
{
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
animatedImages.userInteractionEnabled = YES;
[animatedImages setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview : animatedImages];
[queuePlayer play];
// Array to hold jpg images
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
// Build array of images, cycling through image names
for (int i = 1; i <= IMAGE_COUNT; i++)
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:#"animation(%d).jpg", i]]];
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
// One cycle through all the images takes 1.0 seconds
animatedImages.animationDuration = 12.0;
// Repeat foreverlight electro / 4 sec.
animatedImages.animationRepeatCount = -1;
// Add subview and make window visible
// [self.view addSubview:animatedImages];
animatedImages.image = [imageArray objectAtIndex:imageArray.count - 1];
// Start it up
[animatedImages startAnimating];
// Wait 5 seconds, then stop animation
[self performSelector:#selector(stopAnimation) withObject:nil afterDelay:15000];
}
-(void)playEnded
{
[self performSelector:#selector(playNextItem) withObject:nil afterDelay:5.0];
}
-(void)playNextItem
{
[queuePlayer play];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[scrollView adjustOffsetToIdealIfNeeded];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
[self.tableview reloadData];
}
- (IBAction) scheduleAlarm:(id)sender {
[eventText resignFirstResponder];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// NSDate *selectedDate = [datePicker date]; // you don't need to alloc-init the variable first
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *dc = [cal components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:pickerDate];
pickerDate = [cal dateFromComponents:dc];
NSLog(#"%# is the date in picker date",pickerDate);
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = pickerDate;
// NSLog(#"%#",localNotif.fireDate);
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// NSLog(#"%#",localNotif.timeZone);
// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = #"Show me";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.soundName = #"jet.wav";
// Specify custom data for the notification
NSDictionary *userDict = [NSDictionary dictionaryWithObject:eventText.text
forKey:kRemindMeNotificationDataKey];
localNotif.userInfo = userDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
[self.tableview reloadData];
eventText.text = #"";
viewController = [[TimeViewController alloc] initWithNibName:#"TimeViewController" bundle:nil];
[self presentModalViewController:viewController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
index = indexPath.row;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Warning!!!"
message:#"Are you sure you want to Delete???" delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[alertView show];
[alertView release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notify = [notificationArray objectAtIndex:index];
if(buttonIndex == 0)
{
// Do Nothing on Tapping Cancel...
}
if(buttonIndex ==1)
{
if(notify)
[[UIApplication sharedApplication] cancelLocalNotification:notify];
}
[self.tableview reloadData];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];
return cell;
}
- (void)viewDidUnload {
datePicker = nil;
tableview = nil;
eventText = nil;
[self setScrollView:nil];
[super viewDidUnload];
}
- (void)showReminder:(NSString *)text {
[self onAlarmInvoke];
[self.view addSubview:viewController.view];
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:#"Cancel" otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect rect = self.view.frame;
// if(rect.origin.y <= 480)
// rect.origin.y +=20;
self.view.frame = rect;
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
[player stop];
NSLog(#"OK Tapped");
}
if(buttonIndex == 1)
{
[player stop];
NSLog(#"Cancel Tapped");
}
}
-(IBAction)onTapHome{
viewController = [[TimeViewController alloc] initWithNibName:#"TimeViewController" bundle:nil];
[self presentModalViewController:viewController animated:YES];
}
- (void)dealloc {
[super dealloc];
[datePicker release];
[tableview release];
[eventText release];
[scrollView release];
}
-(IBAction)onTapChange:(id)sender{
SetTimeViewController *viewC = [[SetTimeViewController alloc]initWithNibName:#"SetTimeViewController" bundle:nil];
[self presentModalViewController:viewC animated:YES];
}
#end
Your viewController is probably showing the view, but without the SetViewController's view on the screen you can't see it. Your going to have to first go to the SetViewController and then present your TimeViewController. Is this right, you want to show the SetViewController but call the showReminder: method right away? But only from the didReceiveLocalNotification:.
If this is the case, set a flag,and a text property in your SetViewControllers .h,
BOOL isFromNotification;
NSString *notifText;
and present the SetViewController,and set the flag
SetViewController *setViewController = [SetViewController alloc]........
setViewController.isFromNotification = YES;
setViewController.notifText = reminderText;
[self presentModalViewController animated:YES}
and then in the viewDidAppear: of SetViewController
if(isFromNotification = YES){
[self showReminders:notifText];
}
If I got you right ,
upon notification you would like to show animation on a new view and then show the action sheet ?
Right now you call from appdelegate
[viewController showReminder:reminderText];
which by the way should be self.viewcontroller or _viewcontroller for the actually retained object
In showreminder you call
animation, which in itself adds a subview and by the way is running in the same thread , ie in serial.
and then you add the viewcontroller again as a subview.
and then you try to add the actionsheet from parent to the subview(viewcontroller), when actionsheet should probably be in the viewcontroller itself.
Did i get that right ?
No sure really whats breaking down, could be on several areas, as pointed out above.
I would :
make sure you call the retained objects through valid pointers ( using self for instance)
have a viewcontroller that you present modal as a subview that show animations on a separate thread (performselectoronthread) and have the actionsheet on that.
Then if you need to call the parent, you setup a delegate or you do the ugly way.
self.yourviewcontroller.myParentObj = self
ie set a yourviewcontroller pointer on the sub viewcontroller, which you can then openly call like
[self.myParentObj whatevermethod_you_have_in_parent];
But then again I write this from top of my head..
I have made an app which is an Customized Alarm App. The UILocalNotification should invoke at the time selected by me in UIDatePicker, but is is not invoking at correct timing. For example, I selected the time as 2:00PM for the alarm, so the notification will invoke between 2:00PM and 2:01PM... but not sure when... it is giving me a delay of random time. In my UITableView you can see that it is the description displayed is also comes wrong. I know I am from India so it showing GMT timings, but can it could be corrected?
Here is my whole code:-
-----------------------------AppDelegate.m File :------------------------------
#synthesize window,viewController,timeViewController;
NSString *kRemindMeNotificationDataKey = #"kRemindMeNotificationDataKey";
#pragma mark -
#pragma mark === Application Delegate Methods ===
#pragma mark -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
int x = [[NSUserDefaults standardUserDefaults] integerForKey:#"Mayank"];
if( x == 1 )
{
timeViewController = [[TimeViewController alloc]initWithNibName:#"TimeViewController" bundle:nil];
timeViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect frame = timeViewController.view.frame;
frame.origin = CGPointMake(frame.origin.x,frame.origin.y + statusBarFrame.size.height );
timeViewController.view.frame = frame;
[self.window addSubview:timeViewController.view];
}
else
{
[[NSUserDefaults standardUserDefaults]setInteger:1 forKey:#"Mayank"];
[[NSUserDefaults standardUserDefaults]synchronize];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Do you want to set the Default Alarm?" message:#"at 4:20 PM" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok",nil];
[alert show];
[alert release];
}
sleep(1);
[self.window makeKeyAndVisible];
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotification =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
NSString *reminderText = [localNotification.userInfo
objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
}
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
timeViewController = [[TimeViewController alloc]initWithNibName:#"TimeViewController" bundle:nil];
timeViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect frame = timeViewController.view.frame;
frame.origin = CGPointMake(frame.origin.x,frame.origin.y + statusBarFrame.size.height );
timeViewController.view.frame = frame;
[self.window addSubview:timeViewController.view];
}
if(buttonIndex == 1)
{
viewController = [[SetAlarmViewController alloc]initWithNibName:#"SetAlarmViewController" bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect frame = viewController.view.frame;
frame.origin = CGPointMake(frame.origin.x,frame.origin.y + statusBarFrame.size.height );
viewController.view.frame = frame;
[self.window addSubview:viewController.view];
}
}
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
application.applicationIconBadgeNumber = 0;
}
-----------------------------mainViewController.m File :------------------------------
#implementation SetAlarmViewController
#synthesize datePicker,tableview, eventText,titleBar,setAlarmButton,returnKeyType;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (The420DudeAppDelegate *)[[UIApplication sharedApplication] delegate];
eventText.returnKeyType = UIReturnKeyDone;
// datePicker.minimumDate = [NSDate date];
NSDate *now = [NSDate date];
[datePicker setDate:now animated:YES];
eventText.delegate = self;
index = 0;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
[self.tableview reloadData];
}
- (IBAction) scheduleAlarm:(id) sender {
[eventText resignFirstResponder];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = pickerDate;
// NSLog(#"%#",localNotif.fireDate);
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// NSLog(#"%#",localNotif.timeZone);
// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = #"Show me";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.soundName = #"jet.wav";
// Specify custom data for the notification
NSDictionary *userDict = [NSDictionary dictionaryWithObject:eventText.text
forKey:kRemindMeNotificationDataKey];
localNotif.userInfo = userDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
[self.tableview reloadData];
eventText.text = #"";
viewController = [[TimeViewController alloc] initWithNibName:#"TimeViewController" bundle:nil];
[self presentModalViewController:viewController animated:YES];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
index = indexPath.row;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Warning!!!"
message:#"Are you sure you want to Delete???" delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[alertView show];
[alertView release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notify = [notificationArray objectAtIndex:index];
if(buttonIndex == 0)
{
// Do Nothing on Tapping Cancel...
}
if(buttonIndex ==1)
{
if(notify)
[[UIApplication sharedApplication] cancelLocalNotification:notify];
}
[self.tableview reloadData];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];
return cell;
}
- (void)showReminder:(NSString *)text {
/*
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Reminder"
message:#"hello" delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
[self.tableview reloadData];
[alertView release];
*/
NSString *path = [[NSBundle mainBundle]pathForResource:#"jet" ofType:#"wav"];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
player.numberOfLoops = -1;
[player play];
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet showInView:self.view];
// [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
[player stop];
if(buttonIndex == 0)
{
NSLog(#"OK Tapped");
}
if(buttonIndex == 1)
{
NSLog(#"Cancel Tapped");
}
}
This Pic Shows My App View :
NSDate *pickerDate = [self.pickerTime date];
// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit ) fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
**[dateComps setSecond:00];**
NSDate *itemDate = [calendar dateFromComponents:dateComps];
localNotification.fireDate = itemDate;
just keep in mind, the date from datepicker comes aligned with GMT. you have to convert to your own timezone by yourself. this could be the issue in your case.
I think the problem here has to do with the NSDatePicker returning the seconds of the current time along with the selected time. You need to strip the seconds from the date returned by the NSDatePicker and use that for your alarm and local notification.
NSDate *selectedDate = [datePicker date]; // you don't need to alloc-init the variable first
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *dc = [cal components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:selectedDate];
selectedDate = [cal dateFromComponents:dc];
// now you have an NSDate with zero seconds for your alarm
You should get much better accuracy on your notifications, but I don't think they're guaranteed to be exactly on the split second.
I have a table with all the users events in my app. When you click on one of the events I would like it to save the event name, location, start date, end date, notes in a UILabel. How can I do this my table code is bellow. I have tried searching the web for hours and nothing comes up.
Below is the code for the table
//eventsTable.h
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
#interface eventsTable : UIViewController <UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate> {
IBOutlet UITableView *Table;
EKEventStore *eventStore;
EKEvent *event;
EKEventViewController *detailViewController;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;
}
-(IBAction) done;
- (NSArray *)fetchEventsForToday;
#property (nonatomic, retain)
IBOutlet UITableView *Table;
#property (nonatomic, retain) EKEventStore *eventStore;
#property (nonatomic, retain) EKCalendar *defaultCalendar;
#property (nonatomic, retain) NSMutableArray *eventsList;
#property (nonatomic, retain) EKEventViewController *detailViewController;
#end
//eventsTable.m
#import "eventsTable.h"
#implementation eventsTable
#synthesize eventsList, eventStore, defaultCalendar, detailViewController,Table;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Events List";
// Initialize an event store object with the init method. Initilize the array for events.
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];
// Get the default calendar from store.
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
// Create an Add button
// Fetch today's event on selected calendar and put them into the eventsList array
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
[Table reloadData];
}
-(IBAction) done{
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark Table view data source
// Fetching events happening in the next 24 hours with a predicate, limiting to the default calendar
- (NSArray *)fetchEventsForToday {
NSDate *startDate1 = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate1 = [NSDate distantFuture];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
//NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
// calendars:calendarArray];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate1 endDate:endDate1 calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
events =
[events sortedArrayUsingSelector:
#selector(compareStartDateWithEvent:)];
self.eventsList = [NSMutableArray arrayWithArray:events];
[Table reloadData];
return events;
}
#pragma mark -
#pragma mark Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return eventsList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *result = nil;
if ([tableView isEqual:self.Table] == YES){
static NSString *EventsCellIdentifier = #"Events";
/* We have the index path so let's get the corresponding
event from the array of events */
EKEvent *event1 = [self.eventsList
objectAtIndex:indexPath.row];
/* Try to get a reusable table cell */
result =
[tableView dequeueReusableCellWithIdentifier:EventsCellIdentifier];
if (result == nil){
result = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:EventsCellIdentifier] autorelease];
}
/* The title text of the cell will be the title of the event */
result.textLabel.text = event1.title;
result.textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
result.detailTextLabel.font = [UIFont systemFontOfSize:12.0f];
/* Now let's format the date and the time of the event
and display it as the subtitle of the cell */
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components =
[calendar components:
NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit
fromDate:event1.startDate];
NSDateComponents *components1 =
[calendar components:
NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit
fromDate:event1.endDate];
if ([components hour] == 0 &&
[components minute] == 0 &&
[components second] == 0){
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
NSDate *date = [calendar dateFromComponents: components1];
NSString *string = [NSDateFormatter localizedStringFromDate: date dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterNoStyle];
NSDate *date1 = [calendar dateFromComponents: components];
NSString *string1 = [NSDateFormatter localizedStringFromDate: date1 dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterNoStyle];
result.detailTextLabel.text =
[NSString stringWithFormat:#"All Day from %# - %#",string1,string,
(long)[components month],
(long)[components day],
(long)[components year],
(long)[components1 month],
(long)[components1 day],
(long)[components1 year]];
} else {
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
NSDate *date = [calendar dateFromComponents: components1];
NSString *string = [NSDateFormatter localizedStringFromDate: date dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterShortStyle];
NSDate *date1 = [calendar dateFromComponents: components];
NSString *string1 = [NSDateFormatter localizedStringFromDate: date1 dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterShortStyle];
result.detailTextLabel.text =
[NSString stringWithFormat:#"%# - %#",string1,string,
(long)[components month],
(long)[components day],
(long)[components year],
(long)[components hour],
(long)[components minute],
(long)[components1 hour],
(long)[components1 minute]];
}
}
return(result);
[event release];
[eventsList release];
[eventStore release];
[result release];
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)viewDidUnload {
self.eventsList = nil;
self.view = nil;
self.Table = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
[Table release];
[eventStore release];
[eventsList release];
[defaultCalendar release];
[detailViewController release];
}
#end
Remove the [Table reloadData] and [self.eventsList addObjectsFromArray:[self fetchEventsForToday]]; from viewDidload and place it in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
return [self.eventsList count];
}
Hope this will help you. but it will be better to debug the method [self fetchEventsForToday].
I have an app and in one view is a table. In the table I call the EventStore So It fills the table with your calendar events. I would like to have bars in the table like the ical app on the iphone so It breaks the days up with A bar the bar has the date (ex. March 25, 2011). Below is the code for the table
//eventsTable.h
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
#interface eventsTable : UIViewController <UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate> {
IBOutlet UITableView *Table;
EKEventStore *eventStore;
EKEvent *event;
EKEventViewController *detailViewController;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;
}
-(IBAction) done;
- (NSArray *)fetchEventsForToday;
#property (nonatomic, retain)
IBOutlet UITableView *Table;
#property (nonatomic, retain) EKEventStore *eventStore;
#property (nonatomic, retain) EKCalendar *defaultCalendar;
#property (nonatomic, retain) NSMutableArray *eventsList;
#property (nonatomic, retain) EKEventViewController *detailViewController;
#end
//eventsTable.m
#import "eventsTable.h"
#implementation eventsTable
#synthesize eventsList, eventStore, defaultCalendar, detailViewController,Table;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Events List";
// Initialize an event store object with the init method. Initilize the array for events.
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];
// Get the default calendar from store.
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
// Create an Add button
// Fetch today's event on selected calendar and put them into the eventsList array
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
[Table reloadData];
}
-(IBAction) done{
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark Table view data source
// Fetching events happening in the next 24 hours with a predicate, limiting to the default calendar
- (NSArray *)fetchEventsForToday {
NSDate *startDate1 = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate1 = [NSDate distantFuture];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
//NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
// calendars:calendarArray];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate1 endDate:endDate1 calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
events =
[events sortedArrayUsingSelector:
#selector(compareStartDateWithEvent:)];
self.eventsList = [NSMutableArray arrayWithArray:events];
[Table reloadData];
return events;
}
#pragma mark -
#pragma mark Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return eventsList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *result = nil;
if ([tableView isEqual:self.Table] == YES){
static NSString *EventsCellIdentifier = #"Events";
/* We have the index path so let's get the corresponding
event from the array of events */
EKEvent *event1 = [self.eventsList
objectAtIndex:indexPath.row];
/* Try to get a reusable table cell */
result =
[tableView dequeueReusableCellWithIdentifier:EventsCellIdentifier];
if (result == nil){
result = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:EventsCellIdentifier] autorelease];
}
/* The title text of the cell will be the title of the event */
result.textLabel.text = event1.title;
result.textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
result.detailTextLabel.font = [UIFont systemFontOfSize:12.0f];
/* Now let's format the date and the time of the event
and display it as the subtitle of the cell */
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components =
[calendar components:
NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit
fromDate:event1.startDate];
NSDateComponents *components1 =
[calendar components:
NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit
fromDate:event1.endDate];
if ([components hour] == 0 &&
[components minute] == 0 &&
[components second] == 0){
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
NSDate *date = [calendar dateFromComponents: components1];
NSString *string = [NSDateFormatter localizedStringFromDate: date dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterNoStyle];
NSDate *date1 = [calendar dateFromComponents: components];
NSString *string1 = [NSDateFormatter localizedStringFromDate: date1 dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterNoStyle];
result.detailTextLabel.text =
[NSString stringWithFormat:#"All Day from %# - %#",string1,string,
(long)[components month],
(long)[components day],
(long)[components year],
(long)[components1 month],
(long)[components1 day],
(long)[components1 year]];
} else {
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
NSDate *date = [calendar dateFromComponents: components1];
NSString *string = [NSDateFormatter localizedStringFromDate: date dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterShortStyle];
NSDate *date1 = [calendar dateFromComponents: components];
NSString *string1 = [NSDateFormatter localizedStringFromDate: date1 dateStyle: NSDateFormatterShortStyle timeStyle: NSDateFormatterShortStyle];
result.detailTextLabel.text =
[NSString stringWithFormat:#"%# - %#",string1,string,
(long)[components month],
(long)[components day],
(long)[components year],
(long)[components hour],
(long)[components minute],
(long)[components1 hour],
(long)[components1 minute]];
}
}
return(result);
[event release];
[eventsList release];
[eventStore release];
[result release];
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)viewDidUnload {
self.eventsList = nil;
self.view = nil;
self.Table = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
[Table release];
[eventStore release];
[eventsList release];
[defaultCalendar release];
[detailViewController release];
}
#end
You are going to have to split each day up into a separate section and implement the proper UITableViewDataSource protocols for section indexes: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
Here is a tutorial: http://www.iphonedevcentral.com/indexed-uitableview-tutorial/
If I understand your question correctly, you need to change the section titles with the date you want to display. You do this by implementing the (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method.
You have a problem in your code despite the question. You must release the resources before the return.
return(result);
[event release];
[eventsList release];
[eventStore release];
[result release];