2009-05-28 49 views
1

我正在编程上将两个自定义UIPickerView添加到另一个视图(MainView)。它们工作得很好,但只有在MainView的任何部分发生触摸事件时才能看到它们。我已经检查过UIPickerView和UIView的类引用,但没有发现任何能够“刷新”视图的东西,除非我错过了某些明显的东西?直到触摸发生才显示UIPickerView

这是我在MainView.m中的drawRect方法。我试过在viewDidLoad中做同样的事情,但没有成功。自定义旋转/转换等可以与它有关吗?

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

回答

2

您在视图的控制器中添加子视图,而不是视图本身。我建议您熟悉MVC设计模式。

drawRect只能用于视图本身的实际绘制,而不能用于子视图。

+0

谢谢你,我已经把所有适当的东西都移到了UIViewController中,并且拾取器现在正确显示。 – moigno 2009-05-31 12:48:33