Pregunta

Estoy programáticamente la adición de dos UIPickerViews personalizados a otra vista (MainView). Ellos trabajan muy bien, pero que no son visibles hasta que se produzca un evento de toque en cualquier parte de la MainView. He comprobado las referencias de clases para UIPickerView y UIView pero no he encontrado nada que se las arregla para "refrescar" la vista, a menos que me falta algo obvio?

Esta es mi método drawRect en MainView.m. He intentado hacer lo mismo en viewDidLoad pero sin éxito. ¿Podrían las rotaciones personalizados / etc transforma tener algo que ver con eso?

- (void)drawRect:(CGRect)rect { 
    CGRect pickerFrame = CGRectMake(50, -32, 30, 180);
    m_picker1 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker1.delegate = self;  
    m_picker1.tag = k_ptag1;
    m_picker1.showsSelectionIndicator =YES;  
    m_picker1.backgroundColor = [UIColor clearColor]; 
    CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker1 setTransform:rotate];  
    [self addSubview:m_picker1]; 

    pickerFrame = CGRectMake(50, 67, 30, 180);
    m_picker2 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker2.delegate = self;  
    m_picker2.tag = k_ptag2;
    m_picker2.showsSelectionIndicator =YES;  
    m_picker2.backgroundColor = [UIColor clearColor]; 
    rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker2 setTransform:rotate];  
    [self addSubview:m_picker2];
}
¿Fue útil?

Solución

Se agrega subvistas en el controlador de una vista, no la vista en sí. Yo sugeriría a familiarizarse con el patrón de diseño MVC.

drawRect se supone que sólo se utilizará para el dibujo real de la vista en sí, no subvistas.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top