NimbleKit - fast iOS app development

problem with callback in tableview

Problem discussions

problem with callback in tableview

Postby cactuscraig » Fri Apr 15, 2011 12:55 am

Code: Select all
var myid=10101;
var title="D'or Say";
var mysubtitle="Scottsdale, AZ";
var myimage="";
var mysection=0;
var myimageright=0;
var mycallback="selectCustomer("+myid+",'"+escape(mytitle)+"')";

tableView.insertRecord(mytitle,mysubtitle,myimage,mysection,myimageright,mycallback);

function selectCustomer(id,name) {
     NKAlert (name);
}



With this code, (some removed for easy reading, such as building the tableview) When I tap the row, It does not give me an Alert. seems like a problem with the title. But the title is Escaped, so it should show up, right?
If I change mytitle to something without an apostrophe, it works fine.
All of this data is actually coming from a database using an AJAX Call and being returned as XML. For this example, I have hardcoded the values, but get the same results.

If I try to NKAlert("D%27or"); it fails as well. So something about %27 (')
%20 shows a space. So it is getting unescaped before moving on.

Anyone know how to get this working?
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: problem with callback in tableview

Postby Big-O » Fri Apr 15, 2011 1:15 am

There's too much missing from your code to be sure where the problem is, but you don't seem to be calling the callback correctly.

You've instead put a variable there that contains a string that is a function call but the callback parameter of the insertRecord method needs to be a function name not a variable.
-- Big-O
-- Nimblekit Guru, Web Developer, Hopeless Geek

I do freelance!
http://realisticweb.com
User avatar
Big-O
NimbleKit Guru
 
Posts: 1231
Joined: Thu Sep 24, 2009 4:02 am

Re: problem with callback in tableview

Postby cactuscraig » Fri Apr 15, 2011 1:16 am

ahh... a double escape is in order:

Code: Select all
var mycallback="selectCustomer("+myid+",'"+escape(mytitle)+"')";
tableView.insertRecord(mytitle,mysubtitle,myimage,mysection,myimageright,escape(mycallback));
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: problem with callback in tableview

Postby cactuscraig » Fri Apr 15, 2011 1:17 am

Big-O wrote:There's too much missing from your code to be sure where the problem is, but you don't seem to be calling the callback correctly.

You've instead put a variable there that contains a string that is a function call but the callback parameter of the insertRecord method needs to be a function name not a variable.



function with a variable. I have to pass a variable to my function.
my function then stores the recordiid and the customer name.
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ


Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 0 guests