Skip to content

Instantly share code, notes, and snippets.

@codingricky
Last active June 17, 2019 14:05
Show Gist options
  • Save codingricky/487a081fdf07441b0ca2 to your computer and use it in GitHub Desktop.
Save codingricky/487a081fdf07441b0ca2 to your computer and use it in GitHub Desktop.
robovm callback/bind selector
import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.foundation.NSDictionary;
import org.robovm.apple.uikit.UIApplication;
import org.robovm.apple.uikit.UIApplicationDelegateAdapter;
import org.robovm.apple.uikit.UIBarButtonItem;
import org.robovm.apple.uikit.UIBarButtonSystemItem;
import org.robovm.apple.uikit.UIColor;
import org.robovm.apple.uikit.UINavigationController;
import org.robovm.apple.uikit.UIScreen;
import org.robovm.apple.uikit.UITableViewController;
import org.robovm.apple.uikit.UIViewController;
import org.robovm.apple.uikit.UIWindow;
import org.robovm.objc.Selector;
import org.robovm.objc.annotation.BindSelector;
import org.robovm.rt.bro.annotation.Callback;
public class Play extends UIApplicationDelegateAdapter {
private UIWindow window = null;
@Override
public boolean didFinishLaunching(UIApplication application,
NSDictionary launchOptions) {
UIBarButtonItem barButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, null, null);
Selector selector = Selector.register("add:");
barButtonItem.setAction(selector);
barButtonItem.setTarget(this);
UITableViewController uiTableViewController = new UITableViewController();
uiTableViewController.getNavigationItem().setRightBarButtonItem(barButtonItem);
UINavigationController navigationController = new UINavigationController();
navigationController.addChildViewController(uiTableViewController);
window = new UIWindow(UIScreen.getMainScreen().getBounds());
window.setRootViewController(navigationController);
window.setBackgroundColor(UIColor.colorLightGray());
window.makeKeyAndVisible();
return true;
}
@Callback @BindSelector("add:")
private static void add(Play self, Selector cmd, UIBarButtonItem item) {
System.out.println("add");
}
public static void main(String[] args) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(args, null, Play.class);
pool.close();
}
}
@ntherning
Copy link

Try this:

    @Method
    private void add(UIBarButtonItem item) {
        System.out.println("add");
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment