0

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?

dandan78
  • 13,328
  • 13
  • 64
  • 78
iosdeveloper
  • 99
  • 3
  • 13
  • Check that you have implemented the required datasource function of pickerview:- - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; and - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; – Kuldeep Singh Jan 09 '15 at 08:23
  • i have given above mehods but crashing giving output in console as 2015-01-09 13:58:04.759 SmartWatch[1805:311840] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BSEqualsBuilder numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x17df6da0' – iosdeveloper Jan 09 '15 at 08:28
  • there is no BSEqualsBilder class – iosdeveloper Jan 09 '15 at 08:33
  • sorry no idea about this. – Kuldeep Singh Jan 09 '15 at 08:38

0 Answers0