0

我有一个双选择器和两个 NSInteger 变量,它们更新选择器的每个组件所在的行。在 iPhone 模拟器中(我没有在实际的 iPhone 上测试过),如果我选择行(即单击下方或上方),数字很好,但是当我旋转时,我收到的行号通常与实际相差几个。这是我所拥有的:

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

if (component == kSuitComponent) {
    UIImage *image = self.suitImages[row];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [self theSuitRow];
    return imageView;
}
else {
    NSString *text = self.cardNumber[row];
    UILabel *label = [[UILabel alloc] init];
    [self getCardRow];
    label.text = text;
    return label;
}
}
 -(void) getCardRow {
    cardRow = [_doublePicker selectedRowInComponent:kCardNumberComponent];
}
-(void) theSuitRow {
suitRow = [_doublePicker selectedRowInComponent:kSuitComponent];

}
4

1 回答 1

0

应该:

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

    if (component == kSuitComponent) {
        UIImage *image = self.suitImages[row];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        return imageView;
    }
    else {
        NSString *text = self.cardNumber[row];
        UILabel *label = [[UILabel alloc] init];
        label.text = text;
        return label;
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == kCardNumberComponent) {
        cardRow = row;
    } else {
        suitRow = row;
    }
} 
于 2013-03-15T07:32:54.483 回答