Guest User

Untitled

a guest
Jun 19th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. /*
  2. objc側はwindow - navigationController - yourViewControllerな状態にしておいてjsでviewController生成/pushして画面遷移
  3. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  4. navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  5. [window addSubview:navigationController.view];
  6. [window makeKeyAndVisible];
  7. return YES;
  8. }
  9. */
  10. var w = UIApplication.sharedApplication.keyWindow
  11. var app = UIApplication.sharedApplication
  12. var appDelegate = app.delegate
  13. log(app)
  14. log(appDelegate)
  15. log(appDelegate.viewController)
  16. log(appDelegate.viewController.view)
  17. log(appDelegate.viewController.view.subviews)
  18.  
  19. log(appDelegate.navigationController)
  20. var frame = w.subviews[0]
  21. log(frame)
  22.  
  23. function createCGRect(x,y,w,h) {
  24. var rect = new CGRect();
  25. rect.origin.x = x;
  26. rect.origin.y = y;
  27. rect.size.width = w;
  28. rect.size.height = h;
  29. return rect;
  30. }
  31.  
  32. function createUITextView(text, rect) {
  33. var textView = UITextView.alloc.initWithFrame(rect);
  34. textView.text = text;
  35. return textView;
  36. }
  37.  
  38. function createUITextViewToFit(text) {
  39. var w = UIApplication.sharedApplication.keyWindow;
  40. var frame = w.subviews[0];
  41. var rect = createCGRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
  42. var textView = createUITextView(text, rect);
  43. return textView;
  44. }
  45.  
  46. var newView = createUITextViewToFit("hello, world!\nline 2");
  47. var newViewController = UIViewController.alloc.init
  48. newViewController.view = newView
  49. newViewController.title = 'newView'
  50. // NG
  51. //newViewController.rightButtonHandler = function(){
  52. // log('right button clicked!!!!')
  53. //}
  54. //
  55. //var rightBarButton = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('hell', 0, newViewController, 'rightButtonHandler')
  56.  
  57. // objcのappDelegateに実装したメソッドを指定
  58. var rightBarButton = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('hell', 0, appDelegate, 'rightButtonHandler')
  59.  
  60. newViewController.navigationItem.rightBarButtonItem = rightBarButton
  61.  
  62. // Toolbarにボタン追加
  63. var buttonText = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('ABC', 0, nil, '')
  64. var buttonText2 = UIBarButtonItem.alloc['initWithTitle:style:target:action:']('123', 0, nil, '')
  65. var buttons = [buttonText, buttonText2]
  66. appDelegate.navigationController.toolbarHidden = false
  67. newViewController.toolbarItems = buttons
  68.  
  69. log(newViewController)
  70.  
  71. appDelegate.navigationController['pushViewController:animated:'](newViewController, true)
Add Comment
Please, Sign In to add comment