开发者

Getting a "?" when populating my pickerview on load

I've searched here, but didn't see nothing like this error.

I'm trying to populate my pickerview on ViewDidLoad, but when I run my program, the pickerView is just populated with "?" instead my strings... what's going on here? Thanks in advance.

- (void)viewDidLoad {
    [super viewDidLoad];

    activities = [[NSArray alloc] initWithObjects:@"sleeping", @"eating", @"working", @"think开发者_高级运维ing", @"crying", @"begging", @"leaving", @"shopping", @"hello worlding", nil];

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

}


You need to implement the UIPickerViewDelegate and UIPickerViewDataSource protocols:

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜