0

このコードが機能しない理由がわかりません

このデリゲート メソッドを使用してフォントのサイズを変更しています (関連性がないため、表示する必要はありません)。

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

これはマルチピッカーです。私は3つのコンポーネントを持っています。else を使用して条件付きステートメントでコードを実行すると、セクション 0 がセクション 2 と一致します。これは説明できません。

NSLog(@"%i", component); // only prints, 0, 1, 2
NSString *theString = @"";
if(component == 0){
    theString = [_phosType objectAtIndex:row];
}
if(component == 1){
    theString = [_quantity objectAtIndex:row];
} else {                                        // THIS CAUSES PROBLEMS.
    theString = [_units objectAtIndex:row];
}
pickerViewLabel.text = theString;

これは機能します..何が得られますか!

NSLog(@"%i", component); // only prints, 0, 1, 2
NSString *theString = @"";
if(component == 0){
    theString = [_phosType objectAtIndex:row];
}
if(component == 1){
    theString = [_quantity objectAtIndex:row];
}

if(component == 2){                            // THIS WORKS!  BUT WHY?!
    theString = [_units objectAtIndex:row];
}
pickerViewLabel.text = theString;

component が 2 かどうかを明示的に尋ねる必要があるのはなぜですか? NSLog コンポーネントが 0 1 または 2 以外の値に等しくならないことがわかります。コード内の他の場所で「else」を使用していて、問題が発生しています。誰でもこれを説明できますか?

4

1 に答える 1