gpt4 book ai didi

iphone - DatePicker 不返回我在编辑 View 中创建它时指定的时间/日期

转载 作者:行者123 更新时间:2023-12-03 17:53:11 25 4
gpt4 key购买 nike

iPhone:我正在 iPhone 中执行剩余应用程序,当我从“创建新” View 导航到“编辑” View 时,我需要我的 DatePicker 来显示我刚刚创建剩余部分时已存储的值,因此我需要 DatePicker 返回我在编辑 View 中指定的时间/日期 -Pls Help

1.我的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
`

2我的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.

最佳答案

要在 DatePicker 中显示保存的日期,您需要在 DatePicker 中设置保存的日期。

[datePicker setDate:savedDate 动画:NO];

关于iphone - DatePicker 不返回我在编辑 View 中创建它时指定的时间/日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com