我遇到UIPickerView
的问题。其委托方法:
-(void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component;
当用户点击所选行下方的行时,不会调用。
拾取器设置动画并将“触摸”行放在拾取器的中间但它的旋转不会停止(它继续向上移动约1px并向下移动1px)并且不调用委托方法。
是否有人遇到过同样的问题并且有解决方案?
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow1:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
CGFloat pickerRowRectHeight = PICKER_ROW_HEIGHT;
if (!view)
{
CGFloat rectWidth = 300;
CGRect viewRect = !component ? CGRectMake(0, 0, rectWidth, pickerRowRectHeight) : CGRectMake(0, 0, 50, pickerRowRectHeight);
view = [[[UIView alloc] initWithFrame:viewRect] autorelease];
view.backgroundColor = [UIColor clearColor];
CGRect labelRect = CGRectMake(32 , 0, rectWidth-12, pickerRowRectHeight);
CGFloat fontSize = FONT_SIZE;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(10, 7, 16, 16);
imageView.backgroundColor = [ UIColor clearColor];
imageView.tag = IMAGE_TAG;
[view addSubview:imageView];
[imageView release];
UILabel *label = [[UILabel alloc] initWithFrame:labelRect];
label.lineBreakMode = UILineBreakModeMiddleTruncation;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.font = [UIFont systemFontOfSize:fontSize];
label.tag = LABEL_TAG;
[view addSubview:label];
[label release];
}
UILabel *label = (UILabel *)[view viewWithTag:LABEL_TAG];
label.text = [[someArray objectAtIndex:row] objectForKey:@"title"];
UIImageView *leftImg = (UIImageView*) [view viewWithTag:IMAGE_TAG];
NSData *dataUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[someArray objectAtIndex:row] objectForKey:@"icon"]]];
if (dataUrl!=nil) {
leftImg.image = [UIImage imageWithData: dataUrl];
}
else
{
leftImg.image = [UIImage imageNamed:[[someArray objectAtIndex:row] objectForKey:@"icon"]];
}
view.userInteractionEnabled = NO;
return view;}
答案 0 :(得分:0)
检查您是否分配了选择器视图委托,
- (void)viewDidLoad
{
pickerView.delegate = self;
...