我是Xcode的新手。我想在一个视图中构建两个UIPickerView。第一个UIPickerView中的数据正在按需要进行,但我无法在第二个UIPickerView中获取数据。一个选择器有一个组件,另一个有两个组件。
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
if (pickerView == showData)
return 1;
else
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (pickerView == showData)
switch (tapButton) {
case 1:
return [countryData count];
break;
case 2:
return [serviceData count];
break;
case 3:
return [budgetData count];
break;
default:
return 0;
}
else {
if (component == 0)
return [hourTime count];
else
return [minuteTime count];
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (pickerView == showData)
switch(tapButton)
{
case 1:
return [countryData objectAtIndex:row];
break;
case 2:
return [serviceData objectAtIndex:row];
break;
case 3:
return [budgetData objectAtIndex:row];
break;
default:
return @"nothing";
}
else {
if (component == 0)
return [hourTime objectAtIndex:row];
else
return [minuteTime objectAtIndex:row];
}
}
答案 0 :(得分:1)
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
(NSInteger)component
{
if(component ==0)
{
return [serviceArray count];
}
else {
if ([Service isEqualToString:@"Hair"]) {
return [HairServices count];
}
if ([Service isEqualToString:@"Beauty"]) {
return [BeautyServices count];
}
if ([Service isEqualToString:@"Make Up"])
{
return [MakeUpServices count];
}
if ([Service isEqualToString:@"Eye lash extensions"])
{
return [EyelashServices count];
}
else {
return [HairServices count];
}
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
{
[DisplayArray addObjectsFromArray:HairServices];
if(component ==0)
{
return [serviceArray objectAtIndex:row];
}
else {
if ([Service isEqualToString:@"Hair"]) {
// NSLog(@"DIS %@",DisplayArray);
[DisplayArray removeAllObjects];
[DisplayArray addObjectsFromArray:HairServices];
// NSLog(@" DISPLAY %@", DisplayArray);
return [DisplayArray objectAtIndex:row];
}
if ([Service isEqualToString:@"Beauty"]) {
[DisplayArray removeAllObjects];
[DisplayArray addObjectsFromArray:BeautyServices];
return [DisplayArray objectAtIndex:row]; }
if ([Service isEqualToString:@"Make Up"])
{
[DisplayArray removeAllObjects];
[DisplayArray addObjectsFromArray:MakeUpServices];
return [DisplayArray objectAtIndex:row];
}
if ([Service isEqualToString:@"Eye lash extensions"])
{
[DisplayArray removeAllObjects];
[DisplayArray addObjectsFromArray:EyelashServices];
return [DisplayArray objectAtIndex:row];
}
else {
return [HairServices objectAtIndex:row];
}
}
return 0;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
if (component == 0) {
Service=[[NSString alloc] initWithFormat:@"%@" , [serviceArray
objectAtIndex:row]];
[servicelistPicker reloadComponent:1];
}
else
{
NSLog(@" dis %@",DisplayArray);
if([DisplayArray count]>0)
{
SelectedServices =[NSString stringWithFormat:@"%@,",[DisplayArray
NSLog(@"%@",DisplayArray);
//[TempString appendString:SelectedServices];
ServicesTxt.text = SelectedServices;
ServicesTxt.font = [UIFont boldSystemFontOfSize:13];
}
}
}