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