2011-06-11 64 views
0

我在這裏搜索,但沒有看到這樣的錯誤沒有任何東西。獲取「?」當填充我的pickerview加載

我想填充ViewDidLoad上的pickerview,但是當我運行我的程序時,pickerView只填充了「?」而是我的絃樂......這裏發生了什麼?提前致謝。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    activities = [[NSArray alloc] initWithObjects:@"sleeping", @"eating", @"working", @"thinking", @"crying", @"begging", @"leaving", @"shopping", @"hello worlding", nil]; 

    feelings = [[NSArray alloc] initWithObjects:@"awsome",@"sad",@"happy",@"ambivalent",@"nauseous",@"psyched",@"confused",@"hopeful",@"anxious",nil]; 

} 

回答

2

您需要實現UIPickerViewDelegateUIPickerViewDataSource協議:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 2; 
} 

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
    if (component == 0) 
     return [activities count]; 
    else 
     return [feelings count]; 
} 

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    if (component == 0) 
     return [activities objectAtIndex:row]; 
    else 
     return [feelings objectAtIndex:row]; 
}