UIPicker显示?而不是文字

时间:2013-04-22 19:46:03

标签: ios cocoa-touch uipickerview

我仍然是iOS编码的新手,但我想让我的UIPicker显示我想要的选项,然后能够选择该选项并对其进行操作。但是,而不是让选择器显示我的选择它只是显示?标记而不是我的选择。

这是我的GuardCompany.h

#import <UIKit/UIKit.h>
#define COLOUR 0 

@interface GuardCompany : UIViewController

<UIPickerViewDataSource,UIPickerViewDelegate>{

    IBOutlet UIPickerView *ColourAndShadePicker;

    NSMutableArray *arrayColour;
     }


@end

这是我的GuardCompany.m

#import "GuardCompany.h"

@interface GuardCompany ()

@end

@implementation GuardCompany

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    if (component == COLOUR)
        return [arrayColour count];

    return 0;

}

- (NSString *)GuardCompany:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    if (component == COLOUR)
        return [arrayColour objectAtIndex:row];

    return 0;
}

#pragma mark - view lifecycle

-(void)viewDidLoad
{
    [super viewDidLoad];

    arrayColour = [[NSMutableArray alloc] init];
    [arrayColour addObject:@"red"];
}

@end

1 个答案:

答案 0 :(得分:2)

乍一看,这看起来不正确:

- (NSString *)GuardCompany:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 

将其更改为:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component