简体   繁体   中英

NSView showing and hide SubView

In my applications i need to display and hide based upon some user action, i have done following

In interface definition, have added views like that

@interface MyWnd : NSWindowController {

    MyCustomView1 *pCtmView1; 

    MyCustomView2 *pCtmView2;
}

In source file have following relevant methods

-(void)CreateSubViews{

    NSRect subViewRect = [self GetSubViewRect];

    pCtmView1 = [[ MyCustomView1 alloc]initWithFrame:subViewRect]

    pCtmView2 = [[ MyCustomView2 alloc]initWithFrame:subViewRect]

    initially both view will be hidden 

    [pCtmView1 setHidden:TRUE];
    [pCtmView2 setHidden:TRUE];

    [[self window] view addSubView:pCtmView1];
    [[self window] view addSubView:pCtmView2];
}

-(void)ShowSubView:(int)viewId{
  if(viewId == 0 ){
    [pCtmView1 setHidden:FALSE];
    [pCtmView1 setNeedDisplay:YES];
 }
 if(viewId == 1 ){
    [pCtmView2 setHidden:FALSE];
    [pCtmView2 setNeedDisplay:YES];
 }
}

In Init Application i am Calling ShowSubView:0 and its working fine, but depend upon the some user action, i will call ShowSubView:1 and nothing is displayed & EXEC_BAD_ACCESS i could see in the gdb
Please guide me, do i need to do something more to display the view

Thanks

When your app crashes, look in the Debugger window—it'll tell you what your app was doing when it crashed.

You'll probably want to stop the debugger and re-run your app under Instruments's Zombies instrument. When the crash is because you messaged a dead object (which is the cause probably 80% of the time in Cocoa), the Zombies instrument will tell you what object that was and what killed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM