Guest User

Untitled

a guest
Sep 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Working with ViewControllers in Objective-C
  2. #import "AppDelegate.h"
  3. #import "LoginViewController.h"
  4.  
  5. @implementation AppDelegate
  6.  
  7. @synthesize window = _window;
  8. @synthesize viewController = _viewController;
  9.  
  10. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  11. {
  12. self.viewController = [[LoginViewController alloc] initWithNibName:@"LoginWindowController" bundle:nil];
  13. [self.window setContentView:[self.viewController view]];
  14. }
  15.  
  16. - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
  17.  
  18. [self.window makeKeyAndOrderFront:self];
  19.  
  20. return YES;
  21. }
  22.  
  23. @end
  24.  
  25. #import "LoginViewController.h"
  26.  
  27. @interface LoginViewController ()
  28.  
  29. @end
  30.  
  31. @implementation LoginViewController
  32. @synthesize usernameField;
  33. @synthesize passwordField;
  34.  
  35. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  36. {
  37. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  38. if (self) {
  39. // Initialization code here.
  40. }
  41.  
  42. return self;
  43. }
  44. - (IBAction)loginPressed:(NSButton *)sender
  45. {
  46. NSLog(@"Username = %@", [self.usernameField stringValue]);
  47. NSLog(@"Password = %@", [self.passwordField stringValue]);
  48. }
  49.  
  50. @end
Add Comment
Please, Sign In to add comment