加载我的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];

}
    

解决方法

        您需要实现
UIPickerViewDelegate
UIPickerViewDataSource
协议:
- (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];
}
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...