vp2698
vp2698

Reputation: 1805

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.

Upvotes: 1

Views: 573

Answers (2)

Alok
Alok

Reputation: 25938

Just Create global reference of CalVC *cal as a property . Here your view is deallocating due to local reference .

@property (nonatomic, retain) CalVC * _cal;

Upvotes: 0

tuledev
tuledev

Reputation: 10317

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];

Upvotes: 1

Related Questions