2009-05-28 72 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