0

In default While I create a UIDate picker in my remainder app, when i click done, the current time has to be entered in default or if the date picker is animated the date value can change but in my case the current time is not returned in default ! Please 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.
  • Which is the error? can you post the error means the wrong time & date or some Image for it? – user1673099 Oct 18 '13 at 06:42
  • There is no errors, I need to get the current date in default but i have to click at-least once to set the date. I need the Date to be in "Current Time by Default". -Thank you – Siddarth Hailstorm Oct 18 '13 at 06:53
  • I tried doing " NSLog(@"The notifications is \n %@",notification);" and the log message is : `2013-10-18 12:23:36.010 Remainder[2433:207] The notifications is {fire date = (null), time zone = Asia/Kolkata (IST) offset 19800, repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, October 18, 2013 12:23:36 PM India Standard Time}` – Siddarth Hailstorm Oct 18 '13 at 06:54
  • 1
    Already a descusion carried about this please check the link. http://stackoverflow.com/questions/6340664/delete-a-particular-local-notification –  Oct 25 '13 at 13:42

2 Answers2

1

Already a descusion carried about this please check the link. Delete a particular local notification

Community
  • 1
  • 1
-1

Just add one line after a line in your code

datePicker.datePickerMode = UIDatePickerModeDateAndTime;

Add Below line to your code and try

datePicker.date=[NSDate date];                            
karthika
  • 4,085
  • 3
  • 21
  • 23
Maul
  • 1,179
  • 6
  • 13