您可以在 appDelegate 文件变量中设置 datetimepickervalue。因此,您可以在 appDelegate 文件中定义一个字符串,如下所示
在 appDelegate.h 文件中
NSString *strDate;
@property (nonatomic, 保留) NSString *strDate;
在 appDelegate.m 文件中
@synthesize strDate;
现在,在您的 dateselection 控制器中,在 viewDidLoad 方法中写下一行。
YourAppNameDelegate *appDelegate= [[UIApplication sharedApplication] delegate];
现在,当您完成日期选择并返回第一个视图之前,请执行以下操作。
appDelegate.strDate = [self convertDueDateFormat];
-(NSString *)convertDueDateFormat{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4];
NSString *strDateFormat = NSLocalizedString(@"dateFormat", nil);
[dateFormatter setDateFormat:strDateFormat];
NSString *dateString = [dateFormatter stringFromDate:pkrDueDate.date];
return dateString;
}
现在,在您的 firstviewcontroller.h 文件中使用以下标签。
UILable *lblDate;
在你的 tableview 的 cellForRowIndexPath Datasource 方法中。写在下面。
cell.detailTextLabel.text = @" ";
lblDate = cell.detailTextLabel;
并在 viewWillAppear 方法下面写。
lblDate.text = appDelegate.strDate;