Ui Picker视图错误无法解决

时间:2012-04-07 17:54:19

标签: ios5 uipickerview

仍然试图弄清楚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];
}



}

1 个答案:

答案 0 :(得分: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];
}