Search code examples
objective-cuiviewcontrolleruiwindowaddsubview

add viewcontroller to uiwindow addsubview


//I am Using.

CalVC *cal = [[CalVC alloc]initWithNibName:@"CalVC" bundle:nil];
cal.view.frame = [UIScreen mainScreen].applicationFrame;

[[[[UIApplication sharedApplication] delegate] window] addSubview:cal.view];

It is working and The CalVC appear and i show a calculator in CalVc but when it appear by this method the buttons of calculator not working and show me error //exc_bad_access code=exc_i386_gpflt ios.


Solution

  • I think CalVC was released. So you have to define a property and keep it in .h file.

    @property (nonatomic, strong) CalVC * _cal;
    

    in .m file:

    _cal = [[CalVC alloc]initWithNibName:@"CalVC" bundle:nil];