0

UIPickerView と配列がありますが、配列からすべての日付を UIPicker に入力することはできないようです。

構文は次のようになっていることを知っています。

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
   return [treatments objectAtIndex:row];
}

処理は配列名ですが、これを使用すると次のエラーが発生します。

-[Treatment isEqualToString:]: unrecognized

プロジェクト全体を検索しましたが、次のフレーズが見つかりません。isEqualToString

Treatment.h ファイル:

#import <Foundation/Foundation.h>

@interface Treatment : NSObject {
    NSString *treatmentid;
    NSString *treatmentName;
    NSString *treatmentPrice;
}

@property (nonatomic, strong) NSString *treatmentid;
@property (nonatomic, strong) NSString *treatmentName;
@property (nonatomic, strong) NSString *treatmentPrice;

@end

すべてのピッカー コード:

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [treatments count];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [treatments objectAtIndex:row];
}

さらにコードが必要な場合は、

前もって感謝します

4

1 に答える 1

1

配列に Dictionar または NSMutableDictionar が含まれている場合は、以下のようにキーを使用して配列の値を指定する必要があります。次のようにメソッドを記述してみてください。

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
   return[[treatments objectAtIndex:row]valueForKey:@"YourKey"];
}

ピッカービューのサンプルコードの基本的な実装は次のとおりです:-

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thepickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thepickerView numberOfRowsInComponent:(NSInteger)component
{
        return [treatments count];
}

以下のように UIpickerview の表示ラベルをカスタマイズします:-

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];



        if (component == 0) {

            label.font=[UIFont boldSystemFontOfSize:22];
            label.textAlignment = UITextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];



            label.text = [NSString stringWithFormat:@"%d", row];
            label.font=[UIFont boldSystemFontOfSize:22];

             NSLog(@"%@",[yourpickerview selectedRowInComponent:component]);

        }

    return label;

}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

   NSLog(@"%@",[treatments objectAtIndex:row]);

}
于 2013-07-20T09:18:52.463 に答える