我正在尝试做双重选择器,一部分是文本,另一部分是图像。但是代码给了我一个错误:Thread 1: Program received signal: "EXC_BAD_ACCESS"
。我看不出麻烦。这是代码,Array content Images和Array2内容文本。感谢。
@synthesize Array, picker, Array2;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
UIImage *one = [UIImage imageNamed:@"6-12AM.png"];
UIImageView *oneView = [[UIImageView alloc] initWithImage:one];
NSArray *Array1 = [[NSArray alloc] initWithObjects:oneView, nil];
NSString *fieldName = [[NSString alloc] initWithFormat:@"Array"];
[self setValue:Array1 forKey:fieldName];
Array2 = [[NSArray alloc] initWithObjects:@"Hello", @"trouble", nil];
[super viewDidLoad];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 2;// giving number of components in PickerView
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component;
{
return [self.Array2 count];// counting the number of rows in each component
}
#pragma mark Picker Delegate Methods
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger)row
forComponent:(NSInteger)component
reusingView:(UIView *)view
{
if (component == 1) {
return [self.Array objectAtIndex:row];
}
} //In this line is where the error occurs
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; {
if (component == 0) {
return [self.Array2 objectAtIndex:row];
}
}
答案 0 :(得分:2)
您的错误是由于您没有提供if语句的替代方法。非void函数必须在每种情况下返回一些东西,因此你需要在两个函数中的每一个函数中提供一个else语句,它返回一个值(如nil)。
答案 1 :(得分:0)
我没有看到你分配或初始化Array。因此访问不好。你的意思是使用Array1吗?
还有几件事:
[self setValue:Array1 forKey:fieldName]; //what is this doing?