1

我仍然是 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
4

1 回答 1

2

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

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

将其更改为:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
于 2013-04-22T20:51:15.887 回答