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-17-2012, 09:17 AM   #1 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default Converting String(passed from objc) to Array in Javascript

I am passing a string from objective C to javascript in this way -

Code:
NSArray *array = [NSArray arrayWithObjects:@"10",@"9",@"8", nil];
string = [[array valueForKey:@"description"] componentsJoinedByString:@","];

[graphView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName2([%@])", string]];
and in my javascript I am trying to convert the string into an array by -

Code:
function methodName2(val)
            {
                var b = val;
                var temp = new Array();
                temp = b.split(',');

                alert(temp);
            }
The way I am using to convert does not seem to work. I am wondering if this is because there is a mismatch in the way the javascript understands the "string" being sent to it?

It would be great if someone could help me out with this.
ashwinr87 is offline   Reply With Quote
Old 01-17-2012, 08:57 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Well, so exactly what does happen?

Does the JavaScript function get called? Does it throw an exception and bail out? Or does it just not handle the string the way you want?

FWIW, when I call JavaScript from Objective-C, I format calls to functions taking string arguments like this (as opposed to the way you're formatting it... in particular, the square brackets you're using don't seem like they should work).

Code:
[NSString stringWithFormat:@"methodName2('%@');", string]
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 01-20-2012, 10:34 AM   #3 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default

thanks for the reply..
Apparently, "val" in my javascript accepts the string and stores it as an array... so I did not need to do any formatting....

Quote:
Originally Posted by dljeffery View Post
Well, so exactly what does happen?

Does the JavaScript function get called? Does it throw an exception and bail out? Or does it just not handle the string the way you want?

FWIW, when I call JavaScript from Objective-C, I format calls to functions taking string arguments like this (as opposed to the way you're formatting it... in particular, the square brackets you're using don't seem like they should work).

Code:
[NSString stringWithFormat:@"methodName2('%@');", string]
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: 400
10 members and 390 guests
7twenty7, Atatator, glenn_sayers, guusleijsten, iphonedevshani, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
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:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0