How to set the action for a UIBarButtonItem in Swift

As of Swift 2.2, there is a special syntax for compiler-time checked selectors. It uses the syntax: #selector(methodName). Swift 3 and later: var b = UIBarButtonItem( title: “Continue”, style: .plain, target: self, action: #selector(sayHello(sender:)) ) func sayHello(sender: UIBarButtonItem) { } If you are unsure what the method name should look like, there is a special … Read more

What does metavar and action mean in argparse in Python?

Metavar: It provides a different name for optional argument in help messages. Provide a value for the metavar keyword argument within add_argument(). >>> parser = argparse.ArgumentParser() >>> parser.add_argument(‘–foo’, metavar=”YYY”) >>> parser.add_argument(‘bar’, metavar=”XXX”) >>> parser.parse_args(‘X –foo Y’.split()) Namespace(bar=”X”, foo=’Y’) >>> parser.print_help() usage: [-h] [–foo YYY] XXX positional arguments: XXX optional arguments: -h, –help show this help … Read more

Action Image MVC3 Razor

You can create an extension method for HtmlHelper to simplify the code in your CSHTML file. You could replace your tags with a method like this: // Sample usage in CSHTML @Html.ActionImage(“Edit”, new { id = MyId }, “~/Content/Images/Image.bmp”, “Edit”) Here is a sample extension method for the code above: // Extension method public static … Read more

Uses of Action delegate in C# [closed]

Here is a small example that shows the usefulness of the Action delegate using System; using System.Collections.Generic; class Program { static void Main() { Action<String> print = new Action<String>(Program.Print); List<String> names = new List<String> { “andrew”, “nicole” }; names.ForEach(print); Console.Read(); } static void Print(String s) { Console.WriteLine(s); } } Notice that the foreach method iterates … Read more

android pick images from gallery

Absolutely. Try this: Intent intent = new Intent(); intent.setType(“image/*”); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, “Select Picture”), PICK_IMAGE); Don’t forget also to create the constant PICK_IMAGE, so you can recognize when the user comes back from the image gallery Activity: public static final int PICK_IMAGE = 1; @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode … Read more

commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated

Introduction Whenever an UICommand component (<h:commandXxx>, <p:commandXxx>, etc) fails to invoke the associated action method, or an UIInput component (<h:inputXxx>, <p:inputXxxx>, etc) fails to process the submitted values and/or update the model values, and you aren’t seeing any googlable exceptions and/or warnings in the server log, also not when you configure an ajax exception handler … Read more

Differences between action and actionListener

actionListener Use actionListener if you want have a hook before the real business action get executed, e.g. to log it, and/or to set an additional property (by <f:setPropertyActionListener>), and/or to have access to the component which invoked the action (which is available by ActionEvent argument). So, purely for preparing purposes before the real business action … Read more