Sunday, 16 August 2015

How to open & close a Window? (Cocoa MAC)


hello!

i'm new programming. been reading lot , practicing i'm still in learning phase.

cocoa question (not ios), don't know if should post question here, if not please let me know cocoa forum go to.

have 1 main window, when click button there second window opens. got work i'm unable close first window.

here's code have works open second window:

code:
  - (ibaction)showbflag:(id)sender {            if (!bflagcontrol) {          bflagcontrol = [[ bflagcontroller alloc] initwithwindownibname:@"bflag"];               }            [bflagcontrol showwindow:self];      }    
bflagcontroller class made controls xib file second window.

1 thing tried (i tried several solutions!) instead of closing, reopen first window when click on button on first window second window opens , first window reopens too, works! said should able replace "showwindow" command...? call it? well, thought should able replace showwindow "hidewindow" didn't work.

here tried:

code:
  - (ibaction)showbflag:(id)sender {            if (!bflagcontrol) {          bflagcontrol = [[ bflagcontroller alloc] initwithwindownibname:@"bflag"];          menucontrol = [[ menucontroller alloc] initwithwindownibname:@"mainmenu"];               }            [bflagcontrol showwindow:self];      [menucontrol showwindow:self];      }    
this works instead of "showwindow" think should able use "hidewindow" (for main menu xib)


header file in case is:
code:
  #import <cocoa/cocoa.h>  @class bflagcontroller;    @interface menucontroller : nswindowcontroller {  @private  bflagcontroller *bflagcontrol;    }  - (ibaction)showbflag:(id)sender;      @end    
thanks guys! hope can me or point me in right direction!

----------

i fixed it!

added [self close] @ beginning , worked...

so, how call this:

code:
- (ibaction)showbflag:(id)sender {       [self close];      if (!bflagcontrol) {          bflagcontrol = [[ bflagcontroller alloc] initwithwindownibname:@"bflag"];               }            [bflagcontrol showwindow:self];      }
this method ? object?

thanks!
 

hi, should help.

code:
- (ibaction)click:(id)sender {      if (_window.isvisible) {          [_window close];          [_window2 makekeyandorderfront:nil];      } else {          [_window2 close];          [_window makekeyandorderfront:nil];      }  }
but sure window not release when closes, otherwise bad access error.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment