Last active
June 17, 2019 14:05
-
-
Save codingricky/487a081fdf07441b0ca2 to your computer and use it in GitHub Desktop.
robovm callback/bind selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this: