简体   繁体   English

NSView显示和隐藏SubView

[英]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 在Init应用程序中,我正在调用ShowSubView:0并可以正常工作,但是取决于某些用户操作,我将调用ShowSubView:1,但什么都不会显示&EXEC_BAD_ACCESS我可以在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. 您可能要停止调试器,然后在Instruments的Zombies工具下重新运行您的应用程序。 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. 当崩溃是因为您通知了一个已死的对象(这可能是可可中80%的原因)时,Zombies仪器会告诉您是什么对象以及是什么杀死了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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