Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-24-2012, 05:31 PM   #1 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default Passing date value from objective C to Javascript

I am trying to pass a array of date values from Objective C to Javascript. I tried to pass it this way -
Code:
NSArray *array = [NSArray arrayWithObjects:@"01-03",@"01-05",@"01-07",@"01-09",@"01-11", nil];
self.dateString = [array componentsJoinedByString:@","];
[wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName([%@])", dateString]];
In my Javascript -
Code:
<script>
function methodName(val,val1)
   {
      alert(val1);
   }
</script>
However, what happens here is that the value get displayed as -2, -4, -6, -8, -10 . It literally does a subtraction operation on the values.

Would someone be able to help me out with how I can get this working?
ashwinr87 is offline   Reply With Quote
Old 01-24-2012, 11:44 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2011
Location: Colorado, USA
Posts: 7
ShawnArney is on a distinguished road
Default

I'm guessing the javascript is interpreting this as a number... on the alert call...

i.e. this is what the call looks like to alert:

alert(01-03)

So, it's going to interpret that as a number.

So, you'll need to figure out how to get the javascript to interpret this as a string.

Maybe adding the ' ' as I did below will work??

i.e.
[wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName(['%@'])", dateString]];

Here is a javascript emulator that may be useful for debugging

Tryit Editor v1.5
ShawnArney is offline   Reply With Quote
Old 01-25-2012, 09:46 AM   #3 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default

Thanks for the reply..
this is what I did to get it working -
Code:
NSArray *array = [NSArray arrayWithObjects:@"01-03",@"01-05",@"01-07",@"01-09",@"01-11", nil];

self.dateString = [array componentsJoinedByString:@"','"];

[wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName(['%@'])", dateString]];
Quote:
Originally Posted by ShawnArney View Post
I'm guessing the javascript is interpreting this as a number... on the alert call...

i.e. this is what the call looks like to alert:

alert(01-03)

So, it's going to interpret that as a number.

So, you'll need to figure out how to get the javascript to interpret this as a string.

Maybe adding the ' ' as I did below will work??

i.e.
[wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName(['%@'])", dateString]];

Here is a javascript emulator that may be useful for debugging

Tryit Editor v1.5
ashwinr87 is offline   Reply With Quote
Reply

Bookmarks

Tags
ios5, javascript, objective c

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
12 members and 389 guests
7twenty7, Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0