2010-09-09 39 views
0

我目前正在使用兩個pickerViews的單個視圖。
我發現是這樣的:UIPickerView titleForRow未調用 - 與兩個選擇器查看

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 
{ 
if([thePickerView isEqual:pickerView ]){ 
    return [arrayNo count]; 
} 
else if([thePickerView isEqual:pickerView2]){  
    return [arrayRootNote count]; 
} 

else{ 
    return 0; 
} 

} 
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
if([thePickerView isEqual:pickerView]) 
{ 
    return [arrayNo objectAtIndex:row]; 
} 
else if([thePickerView isEqual:pickerView2]){  
    return [arrayRootNote objectAtIndex:row]; 
} 

else{ 
    return [arrayRootNote objectAtIndex:row]; 
} 

NSLog(@"I am a called method"); 
} 

我要的是改變每個挑選(由兩個NSMutableArrays填充)的稱號。 問題是兩個採集器顯示pickerView的「ArrayNo」。

我發現調試器(和NSLog)的方法titleForRow根本沒有被調用。
有什麼想法?在此先感謝

Séraphin

回答

1

問題就迎刃而解了:
viewForRow,我需要改變自定義標籤我所做的:

- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ 

CGRect rect = CGRectMake(0, 0, 188.25, 70.4); 
UILabel *label = [[UILabel alloc]initWithFrame:rect]; 
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2); 
rotate = CGAffineTransformScale(rotate, 0.22, 1.7); 

[label setTransform:rotate]; 
//label.text = [arrayNo objectAtIndex:row];   THAT was the error. 

if([thePickerView isEqual:pickerView])    THAT is the solution. 
{ 
label.text = [arrayNo objectAtIndex:row]; 
    } 
else if([thePickerView isEqual:pickerView2]){  
label.text = [arrayRootNote objectAtIndex:row]; 
} 

label.font = [UIFont fontWithName:@"Georgia" size:50]; 
label.textAlignment = UITextAlignmentCenter; 
label.numberOfLines = 2; 
label.lineBreakMode = UILineBreakModeWordWrap; 
label.backgroundColor = [UIColor clearColor]; 
label.clipsToBounds = YES; 
return label ; 
} 
1

您是否設置委託/數據源?

+0

感謝您的快速答覆!一切都與IB有關。 pickerView在pickerView上,pickerView2在pickerView2上!我也做了pickerView.delegate = self – 2010-09-09 19:37:24

+0

問題解決!我在viewForRow中犯了一個錯誤,我忘記了我有一個自定義標籤! – 2010-09-11 19:53:48