我在UIPickerView中遇到问题。我正在尝试根据以下方法创建UIImageView
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
在上面的方法中我放了一个条件.i.e if(view == nil)
但是它总是返回视图为nil,它不会进入else条件。
代码是
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
if(view == nil)
{
UIView *rowView;
rowView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 22)] retain];
[rowView setBackgroundColor:[UIColor clearColor]];
UIImageView *checkOrUncheck = [[UIImageView alloc] initWithFrame:CGRectMake(40, 1, 18, 18)];
[checkOrUncheck setImage:nil];
[checkOrUncheck setTag:-100];
UIButton *rowLabel = [UIButton buttonWithType:UIButtonTypeCustom];
rowLabel.frame = CGRectMake(70, 1, 904, 20);
[rowLabel setBackgroundColor:[UIColor clearColor]];
[rowLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[rowLabel.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:22]];
rowLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[rowLabel setTag:-101];
if([pickerView isEqual:returnDatePicker])
{
[rowLabel setTitle:[returnDatesDurationArray objectAtIndex:row] forState:UIControlStateNormal];
}
else if([pickerView isEqual:selectProductPicker])
{
NSMutableDictionary *dict = [selectProductsArray objectAtIndex:row];
[rowLabel setTitle:[dict objectForKey:@"Name"] forState:UIControlStateNormal];
}
[rowView addSubview:checkOrUncheck];
[rowView addSubview:rowLabel];
}
else
{
NSLog(@"no");
}
return rowView;
}
请告诉我代码中的错误。感谢您花时间留言。