NSDate and UIWebView

154 views Asked by At

I have a Date displayed in a UIlabel in my main view controller with a date picker that changes the date in the UILabel. I have UIWebViews that change based on the date. How do I pass the date displayed in the UILabel to the UIWebview?

Thanks in advance

1

There are 1 answers

10
Ashish Bindal On

Add the target and selector for event: UIControlEventValueChanged and then simply call the javascript function from the selector.

//set the selector for datePicker event
[datePicker addTarget:self action:@selector(dateChanged)  forControlEvents:UIControlEventValueChanged]; 
.......
.......
-(IBAction)dateChanged
{
     .......
     .......
     //call the javascript function text=>data to show
     NSString  *string = [NSMutableString stringWithFormat:@"showTextFromNative( %@)", text];    
     [self.webviewOutlet stringByEvaluatingJavaScriptFromString:string];
}


//javascript function in your html
function showTextFromNative(text) 
{ 
 ....
 ....///Do what ever you want to show in webview
 ....
}