Setting Button action from XML - ios

I have buttons who's action function changes based on a certain configuration XML. I'm looking to change the button action based on the XML.
Example, I will parse this XML node and finally should be able to set the target as doLoginSecure for the button loginButton. The doLoginSecure method action be already defined in the iOS code.
<button name="loginButton" target="doLoginSecure">
How do I do this ?

[someButton addTarget:self action:NSSelectorFromString(#"yourMethod") forControlEvents:UIControlEventTouchUpInside];
replace yourMethod string with XML value

I would suggest,
Instead of assigning target to button as per xml why not you write one function which will be assigned to that button and in that use switch case which will be execute as per the xml response.
Let say, you have loginbutton, so from xml you will be getting two function like fun1 or fun2.
Assign fun fucntion at start to loginbutton.
While parsing xml response set sone variable as 1 or 2 depending on the fucntion
say if fucntionname it fun1 then it is 1 and if it is fun2 then 2.
Now in fun,
-(void)fun:(int)icheck
{
switch(iCheck)
{
case 1:fun1();
break;
case 2:fun2();
break;
//......and like this
}
}

Related

How do get custom functions to recalculate in google sheets?

I created a custom function for google spreadsheets. All it does is return a random letter. The function works great when I first enter it into a cell. But now I want to be able to "recalculate" the function using a keyboard shortcut; I'd also be willing to refresh the page if needed.
TLDR: I want to be able to hit a key and have my custom functions recalculate.
How can I accomplish this?
Edit to add:
Here is the code for my function.
//returns a random letter suitable for use in function notation
function ranFunLet() {
var letters = ['a','b','c','d','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z']
var letter = letters[Math.floor(Math.random()*letters.length)];
//console.log(letter);
return letter;
}
I would like the cell I use it in to run the function again when I press a button (or refresh the page).
Suggestion
The Apps Script editor does support keyboard shortcut trigger as per this existing answer. However, you may want to try Importing functions as macros, then you can assign a unique keyboard shortcut to it.
Here's a sample
Sample Sheet
Sample script function to test
This sample script function increments the number on A1 cell.
function sample() {
var data = SpreadsheetApp.getActive().getActiveSheet().getRange("A1").getValue();
var res = data+1;
SpreadsheetApp.getActive().getActiveSheet().getRange("A1").setValue(res);
}
Import the function on your spreadsheet (in my testing it is named as sample):
In the Google Sheets UI, select Tools > Macros > Import.
Select a function form the list presented and then click Add
function.
Select clear to close the dialog.
Select Tools > Macros > Manage macros.
Locate the function you just imported in the list. Assign a unique
keyboard shortcut to the macro. You can also change the macro name
here; the name defaults to the name of the function.
Click Update to save the macro configuration.
Result
After pressing the sample shortcut key Ctrl + Alt + Shift + 2, the function incremented the number on A1 cell from 1 to 2:
NOTE: You can not choose a specific shortcut & if you'll edit your function on the Apps Script editor, you would need to re-import your function again as a macro.
the button solution is done like this:
https://www.youtube.com/watch?v=yaBMsSpAxYM

Actionscript components events

I have a project where I am trying to use multiple components in an ActionScript. I have a numeric stepper and text input and a couple buttons. The trouble is the events they dispatch in these components are similar (eg the "click" event), and I am getting a mishmash of scope problems trying to handle this. What I did was create a function in my .as file that had a switch statement to catch multiple "click" events, but for some reason the numeric stepper still is not playing well with the others and keeps setting the instance value to "undefined", probably because there is a scope issue.
Anyway here is a portion of the code that I think is where there is trouble.
(vars: plus_Btn and minus_Btn are button objects, they increment/decrement a private variable by adding or subtracting the value on the numeric stepper which is called stepSize_NS.)
stepSize_NS.addEventListener("click", this);
plus_Btn.addEventListener("click", this);
minus_Btn.addEventListener("click", this);
function click(evt:Object):Void{
switch (evt.target){
case minus_Btn:
command -= stepSize_NS.value;
break;
case plus_Btn:
command += stepSize_NS.value;
break;
case stepSize_NS:
trace("Step Size changed to " + stepSize_NS.value);
//eventually this will do something else whenever the stepper chngs
break;
default:
break;
}//end switch
}//end function

eVar value not getting passed in s.tl call

I have a page that contains a login form. I am calling a separate function (which resides in a separate .js file) on the onsubmit event of the form. Below is the function
var LoginClick = function() {
// Omniture Code
s.linkTrackVars="events, eVar1";
s.linkTrackEvents="event1";
s.events="event1";
s.eVar1="Login";
s.tl(true, "o", "Login Clicks");
};
while the events data is getting passed on the s.tl call, the evar1 value turns up as "none" in the conversion report. I used a packet sniffer (omnibug) to check the values being passed. Even though s.eVar1 is assigned the value "Login" it does not pass that value.
Ofcourse, s.t() works well (evar value gets passed) but I dont want to do that.
I have tried s.tl(this, "o"...) which doesnt work either.
What am I doing wrong here?
Appreciate your time and help.
remove the space between the comma and eVar1
s.linkTrackVars="events, eVar1"
should be
s.linkTrackVars="events,eVar1"

Issue with using int.parse() in Dart

I'm currently teaching myself the Dart language, and my first app doesn't seem to be working right. Here's the code that's causing trouble:
usrLoc = int.parse(query("#txtLoc").text);
When I try to run the app, it opens fine, but when I click the button that triggers this (and three other similar parses), the debugger stops and tells me "Source not found" for int._native_parse(), int._parse(), and int.parse().
Any help would be greatly appreciated.
The text property for the specified element #txtLoc returns an empty string.
The parse method requires that:
The source must be a non-empty sequence of base- radix digits, optionally prefixed with a minus or plus sign ('-' or '+').
You can specify an onError named argument in your call to parse, which takes a callback that handles the invalid input. E.g., if you want the parse call to return the value 42 for all invalid input, you can do this:
usrLoc = int.parse(query("#txtLoc").text, onError: (val) => 42);
If you really expect the element to have some text, you can store the result of query("#txtLoc").text into a separate variable and verify the value. It would also be interesting to check what the real element type is or which tag is marked with id #txtLoc.
If you want to get the content of an input element, you should use the value property instead of text:
query("#txtLoc").value

jQuery autocomplete not displaying my encoded values

I am working from this example: http://jqueryui.com/demos/autocomplete/#remote and I am encoding the output like this:
$rows = array();
while($r = mysql_fetch_assoc($category_result))
{
$rows[] = $r;
error_log ("rows: ".$rows[0]);
}
echo json_encode($rows);
But the dropdown on the other side shows nothing. Here is my test page: http://problemio.com/test.php - if you enter "ho" it matches 2 results in the database, but they are not getting displayed for some reason. Any idea why?
Thanks!!
The properties should be named label and value. From the JQuery UI demo page you linked to:
The local data can be a simple Array of Strings, or it contains
Objects for each item in the array, with either a label or value
property or both. The label property is displayed in the suggestion
menu.
So you would need to rename category_name to label either in PHP or later on in your JavaScript source handler function. The latter would require you to replace the PHP URL with a callback function like in the remote example. That way you could get the data any way you want (e.g. by jQuery.getJSON()) and work with it before it gets handed over to the suggestion box.
Hope this helps.
Regarding your comment, this should do it:
$rows = array();
while ($r = mysql_fetch_array($category_result)) {
$rows[] = array("label" => $r["category_name"]);
}
echo json_encode($rows);

Resources