我目前正在使用两个pickerViews处理单个View 我找到了类似的东西:
- (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方法。
任何的想法?提前致谢
塞拉芬
答案 0 :(得分:1)
你设置了委托/数据源吗?
答案 1 :(得分: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 ;
}