这是我显示pickerview的代码。
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *pickerLabel = (UILabel *)view;
CGSize limitSize = CGSizeMake(300.0f, 50.0f);
CGSize textSize;
CGRect labelRect;
switch ([pickerView tag]) {
case 1: //Quiz picker
{
//m_txtPurpose.text=@"Test";
QuizGenre *quiz = [m_arrQuizGenre objectAtIndex:row];
NSString *title = [quiz m_quizGenreName];
textSize = [title sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:limitSize lineBreakMode:UILineBreakModeWordWrap];
labelRect = CGRectMake(0, 0, textSize.width, textSize.height);
NSLog(@"length:%i title:%@",[title length],title);
NSLog(@"h:%f w:%f",textSize.height,textSize.width);
if (pickerLabel == nil)
{
pickerLabel = [[[UILabel alloc] initWithFrame:labelRect] autorelease];
[pickerLabel setFont:[UIFont systemFontOfSize:14]];
[pickerLabel setBackgroundColor:[UIColor clearColor]];
[pickerLabel setLineBreakMode:UILineBreakModeWordWrap];
[pickerLabel setTextAlignment:UITextAlignmentCenter];
[pickerLabel setText:title];
[pickerLabel setNumberOfLines:3];
}
break;
case 2: //Purpose picker
{
//cost.text = @"ABC";
Purpose *prp = [m_arrPurpose objectAtIndex:row];
NSString *title = [prp m_purposeName];
textSize = [title sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:limitSize lineBreakMode:UILineBreakModeWordWrap];
labelRect = CGRectMake(0, 0, textSize.width, textSize.height);
NSLog(@"length:%i title:%@",[title length],title);
NSLog(@"h:%f w:%f",textSize.height,textSize.width);
if (pickerLabel == nil)
{
pickerLabel = [[[UILabel alloc] initWithFrame:labelRect] autorelease];
[pickerLabel setFont:[UIFont systemFontOfSize:14]];
[pickerLabel setBackgroundColor:[UIColor clearColor]];
[pickerLabel setLineBreakMode:UILineBreakModeWordWrap];
[pickerLabel setTextAlignment:UITextAlignmentCenter];
[pickerLabel setText:title];
[pickerLabel setNumberOfLines:3];
}
break;
default:
break;
}
}
}
return pickerLabel;
}
我的 Picker 视图在第 6 行后显示错误值。我的测验选择器视图中有 13 个值。像测验类型:1>艺术2>地理3>常识到13号>电视。在第 6 个值之后,它从第一条记录开始。这是图像
安装它应该显示类似这样的东西。电影、音乐、电视、政治等等。您的帮助将不胜感激。谢谢