Passing NSDate to local UIWebView in iOS - Goal C

I have a menu application that loads various UIWebViews that are loaded from local HTML files. (this code is in the WebViewController)

//Code for the WebView
vesperswebview.scrollView.bounces = NO;
[[vesperswebview scrollView] setBounces:NO];
[(UIScrollView*)[vesperswebview.subviews objectAtIndex:0] setShowsVerticalScrollIndicator:NO];

NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"data/html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSString *theAbsoluteURLString = [url absoluteString];
NSString *queryString = @"#?manifest=Psalmody-Morning";
NSString *absoluteURLwithQueryString = [theAbsoluteURLString stringByAppendingString:queryString];
NSURL *finalURL = [NSURL URLWithString:absoluteURLwithQueryString];

NSURLRequest *request = [NSURLRequest requestWithURL:finalURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:(NSTimeInterval)10.0];
[vesperswebview loadRequest:request];

I also have a custom date picker called FlatDate Picker: (this code is in my main ViewController). It is related to the imported OpenDatePicker open source project I received from GitHub.

- (void)flatDatePicker:(FlatDatePicker*)datePicker dateDidChange:(NSDate*)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSCalendar *coptic = [[NSCalendar alloc] initWithCalendarIdentifier:@"coptic"];
    [dateFormatter setCalendar:coptic];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];

    if (datePicker.datePickerMode == FlatDatePickerModeDate) {
        [dateFormatter setDateFormat:@"EEEE, MMMM, dd, yyyy"];
    } else if (datePicker.datePickerMode == FlatDatePickerModeDate) {
        [dateFormatter setDateFormat:@"HH:mm:ss"];
    } else {
        [dateFormatter setDateFormat:@"EEEE, MMMM, dd, yyyy HH:mm:ss"];
    }
    NSString *value = [dateFormatter stringFromDate:date];
    self.labelDateSelected.text = value;
}

My question is: when I select a date in my main view controller, how can this date be saved and passed to the next view in order to load the corresponding Javascript, which is sensitive to the date of time in my database

+4
2

, FlatDatePicker, JavaScript DateFormats

"2015-03-25" ( )

"03/25/2015" "2015/03/25"

"25 2015 " "25 2015 "

NSDate . :

NSDateFormatter *ISODateFormatter = [[NSDateFormatter alloc] init];
[ISODateFormatter setDateFormat:@"yyyy-mm-dd"];

NSDateFormatter *ShortDateFormatter = [[NSDateFormatter alloc] init];
[ShortDateFormatter setDateFormat:@"yyyy/mm/dd"];

NSDateFormatter *LongDateFormatter = [[NSDateFormatter alloc] init];
[LongDateFormatter setDateFormat:@"dd MMM yyyy"];

NSString *ISODate = [ISODateFormatter stringFromDate:date];
NSString *ShortDate = [ShortDateFormatter stringFromDate:date];
NSString *LongDate = [LongDateFormatter stringFromDate:date];

selectedDate. init UIViewController,

@interface JSViewController ()

@property (nonatomic, strong) NSString *currentDate;

@end

-(instancetype)initWithDate:(NSString *)jsDate {
     self = [super initWithNibName:NULL bundle:NULL];
     if (self) {
       _currentDate = jsDate;
     }
     return self;
 }

ViewController , .

JSViewController *jsVC = [[JSViewController alloc] initWithDate:ISODate];
[self presentViewController:jsVC animated:YES completion:nil];

. , . , .

+1

stringByEvaluatingJavaScriptFromString ( UIWebView) evaluateJavaScript:completionHandler: ( WKWebView) JavaScript, html.

Segues WebViewController ViewController, prepareForSegue :

- (void)prepareForSegue: (UIStoryboardSegue *)segue sender: (id)sender {
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString: @"SEGUE_NAME"]) {
        // Get reference to the WebViewController
        WebViewController *vc = [segue destinationViewController];

        // Pass the date to the WebViewController
        [vc setSelectedDate: mySuperAwesomeDate];
    }
}
+1

Source: https://habr.com/ru/post/1656751/


All Articles