My app is related to the custom views. In single view controller, there are 14 buttons. When each button is clicked, custom view containing picker view should appear along with ok and cancel buttons and transparent background. I have written code for that and the app gets crashing when I am trying to add picker view to the main view. My code is as below.
-(custompickerview *)sharedInstance{
static custompickerview *myInstance = nil;
if (nil == myInstance) {
myInstance = [[[self class] alloc] initWithView];
}//End of if statement
myInstance.window = [[UIWindow alloc] initWithFrame:[UIScreen
mainScreen].bounds];
myInstance.window.windowLevel = UIWindowLevelStatusBar;
myInstance.window.hidden = YES;
myInstance.window.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
return myInstance;
}
-(id)initWithView{
NSArray *arrayOfViews;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"custompickerview"
owner:nil
options:nil];
}else{
arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"custompickerview"
owner:nil
options:nil];
}
if ([arrayOfViews count] < 1){
return nil;
}
custompickerview *newView = [arrayOfViews objectAtIndex:0];
//[newView setFrame:frame];
newView.layer.cornerRadius = 10.0;
newView.layer.borderColor = [UIColor blackColor].CGColor;
newView.clipsToBounds = YES;
self = newView;
return self;
}
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *view in self.subviews) {
if (!view.hidden && view.alpha > 0 && view.userInteractionEnabled && [view
pointInside:[self convertPoint:point toView:view] withEvent:event])
return YES;
}
[self didCustomPopUpUnload];
return NO;
}
- (void)didCustomPopUpAlertLoad:(UIView *)parentView andtitle:(NSString
*)strTitle {
[self setRootView:parentView];
[parentView addSubview:_pickerview];
//Add alertview into transparent view to hide parent view interaction
UIView *transparentView = [[UIView alloc] initWithFrame:parentView.bounds];
[transparentView setBackgroundColor:[UIColor clearColor]];
//[transparentView addSubview:_pickerview];
[transparentView addSubview:self];
float x = (int)(transparentView.bounds.size.width - self.bounds.size.width)>>1;
float y = (int)(transparentView.bounds.size.height - self.bounds.size.height)>>2;
[self setFrame:CGRectMake(x, y+62, self.bounds.size.width,
self.bounds.size.height)];
// [self setFrame:CGRectMake(x+10, y+62, self.bounds.size.width, self.bounds.size.height)];
[self.window addSubview:transparentView];
[self.window makeKeyAndVisible];
}
I might be wrong in adding sub view to parent view. Is there any sample code how to add the picker view to the custom views?