Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- objc側はwindow - navigationController - yourViewControllerな状態にしておいてjsでviewController生成/pushして画面遷移
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [window addSubview:navigationController.view];
- [window makeKeyAndVisible];
- return YES;
- }
- */
- var w = UIApplication.sharedApplication.keyWindow
- var app = UIApplication.sharedApplication
- var appDelegate = app.delegate
- log(app)
- log(appDelegate)
- log(appDelegate.viewController)
- log(appDelegate.viewController.view)
- log(appDelegate.viewController.view.subviews)
- log(appDelegate.navigationController)
- var frame = w.subviews[0]
- log(frame)
- function createCGRect(x,y,w,h) {
- var rect = new CGRect();
- rect.origin.x = x;
- rect.origin.y = y;
- rect.size.width = w;
- rect.size.height = h;
- return rect;
- }
- function createUITextView(text, rect) {
- var textView = UITextView.alloc.initWithFrame(rect);
- textView.text = text;
- return textView;
- }
- function createUITextViewToFit(text) {
- var w = UIApplication.sharedApplication.keyWindow;
- var frame = w.subviews[0];
- var rect = createCGRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
- var textView = createUITextView(text, rect);
- return textView;
- }
- var newView = createUITextViewToFit("hello, world!\nline 2");
- var newViewController = UIViewController.alloc.init
- newViewController.view = newView
- newViewController.title = 'newView'
- // NG
- //newViewController.rightButtonHandler = function(){
- // log('right button clicked!!!!')
- //}
- //
- //var rightBarButton = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('hell', 0, newViewController, 'rightButtonHandler')
- // objcのappDelegateに実装したメソッドを指定
- var rightBarButton = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('hell', 0, appDelegate, 'rightButtonHandler')
- newViewController.navigationItem.rightBarButtonItem = rightBarButton
- // Toolbarにボタン追加
- var buttonText = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('ABC', 0, nil, '')
- var buttonText2 = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('123', 0, nil, '')
- var buttons = [buttonText, buttonText2]
- appDelegate.navigationController.toolbarHidden = false
- newViewController.toolbarItems = buttons
- log(newViewController)
- appDelegate.navigationController['pushViewController:animated:'](newViewController, true)
Add Comment
Please, Sign In to add comment