Uso de subvistas en scrollerview iPhone

I am trying to add uipickerview in uiscrollview, but it is not being shown properly, just a black square.

Further, I have to add 1 more uipickerview, some labels and some buttons.

El código que estoy usando es el siguiente:

-(void)loadView {

    [super loadView];

    UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];
    scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scroller.pagingEnabled = YES;
    NSInteger numberOfViews = 2;
    for (int i = 0; i < numberOfViews; i++) {
        CGFloat yOrigin = i * self.view.frame.size.height;
        UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
       // awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
        [scroller addSubview:awesomeView];
        [scroller addSubview:pView];

    }
    scroller.contentSize = CGSizeMake(self.view.frame.size.width , self.view.frame.size.height * numberOfViews);
    [self.view addSubview:scroller];

}

¿Cuál puede ser el problema?

preguntado el 10 de marzo de 12 a las 14:03

Is the app actually starting? Because as far as I remember, calling self.view from -loadView starts an infiniteLoop. Try using self.view = scroller; en lugar de. -

yes, application is starting properyl -

3 Respuestas

Are you putting data in the picker view? I mean, if you just put the picker view without data on it you are not going to see anything on it.

You need to add the delegate and the datasource and put some data in your picker!

pView.delegate = self;
pView.datasource = self;

and then you have to implemente at least:

numberOfComponentsInPickerView:
numberOfRowsInComponent: 
titleForRow:

respondido 10 mar '12, 14:03

make sure you are implementing uipickerviewdelegate methods. its normal that it will show just the black square because your pickerview cant find the data and thus does not display anything.

respondido 10 mar '12, 17:03

UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];

Cambiar altura a 216 .. UIPickerView has fixed height of 216 ..only.. you can't change it..

respondido 10 mar '12, 14:03

I have already tried that, we can modify the height of picker view. - Ömer Waqas Khan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.