0

仍在尝试找出 UI 选择器视图,现在已经有 2 天了,出于某种原因,我只是坚持这一点。请就我做错了什么提供任何建议。我有一个黄色三角形表示“不完整的实现”和一个红色三角形表示“使用未声明的标识符 numberOfComponentsinPickerView”

。H

#import <UIKit/UIKit.h>

@interface pick3 : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {  


UIPickerView *select;    
NSArray *list;


}



@property (strong, nonatomic) IBOutlet UIPickerView *select;




@end

.m

#import "pick3.h"

@interface pick3 ()

@end

@implementation pick3
@synthesize select;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.




{

     list = [[NSArray alloc] initWithObjects:@"Employed", @"Student", @"Retired",     @"Homemaker", @"Self-employed", @"Unemployed", @"Other", nil];
}

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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    //set number of rows
    return list.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    //set item per row
    return [list objectAtIndex:row];
}



}
4

1 回答 1

1

这只是你viewDidLoad:方法上的一个错字。

您的“列表”之前有一个额外的“{”,文件末尾有一个额外的“}”。只需删除它们就可以了。

试试这个:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

     list = [[NSArray alloc] initWithObjects:@"Employed", @"Student", @"Retired",     @"Homemaker", @"Self-employed", @"Unemployed", @"Other", nil];
}
于 2012-04-07T20:20:27.617 回答