Ios 选择器视图选项填充标签
我希望我的选择器视图在用户选择某些选项时填充标签。 示例:组件1选项显示在标签1中,组件2选项显示在标签2中,组件3选项显示在标签3中 对于普通的选择器,我不会有任何问题,但是我的选择器组件会根据上一个组件的选择而改变 例如: 组件1中的第一个选项显示组件2中的数据 组件1中的第二个选项显示组件2中的不同数据 进而显示组件3中的不同数据 它目前没有按照我的要求运行和运行,我不知道我做错了什么。我想这是我的didSelectRow部分,但不是很确定 h 在didSelectRow方法中,每个case语句都缺少一个break语句Ios 选择器视图选项填充标签,ios,objective-c,uilabel,uipickerview,Ios,Objective C,Uilabel,Uipickerview,我希望我的选择器视图在用户选择某些选项时填充标签。 示例:组件1选项显示在标签1中,组件2选项显示在标签2中,组件3选项显示在标签3中 对于普通的选择器,我不会有任何问题,但是我的选择器组件会根据上一个组件的选择而改变 例如: 组件1中的第一个选项显示组件2中的数据 组件1中的第二个选项显示组件2中的不同数据 进而显示组件3中的不同数据 它目前没有按照我的要求运行和运行,我不知道我做错了什么。我想这是我的didSelectRow部分,但不是很确定 h 在didSelectRow方法中,每个cas
你可能还想考虑使用现代Objto-C,它更容易阅读< /P>什么错误?您需要向任何人提供更多详细信息以提供帮助。此外,为了将来,请尝试将代码格式化为尽可能可读的格式。这次我是为你做的,看一看,这对我们理解你的问题有很大帮助。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *picker1;
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UILabel *label3;
@end
#import "ViewController.h"
@interface ViewController ()
{
NSArray*overalltype;
NSArray*healthtype;
NSArray*midwifetype;
NSArray*doctortype;
NSArray*otherhealthtype;
NSArray*visitorstype;
NSArray*othertype;
NSArray*onlinetype;
NSArray*volunteertype;
NSInteger selectedOptionFromColumn1;
NSInteger selectedOptionFromColumn2;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
overalltype =[[NSArray alloc]initWithObjects:@"Health Professional", @"HouseKeeping",@"Visitors", @"Other",nil];
healthtype =[[NSArray alloc]initWithObjects:@"Midwife", @"Nurse",@"Doctor", @"Other Health Professional" ,nil];
midwifetype =[[NSArray alloc]initWithObjects:@"Known Midwife", @"New Midwife", nil];
doctortype =[[NSArray alloc]initWithObjects:@"Snr Dr", @"Jnr Dr", @"Baby Dr", @"GP", nil];
otherhealthtype =[[NSArray alloc]initWithObjects:@"Lactation Consultant", @"Student", @"Hearing Technician", @"Bloody Collector", @"Social Worker", @"Mental Health", @"Physiotherapist", nil];
visitorstype =[[NSArray alloc]initWithObjects:@"Partner", @"Relatives", @"Friends", @"Other Woman's Visitors", nil];
othertype =[[NSArray alloc]initWithObjects:@"Online Support", @"Volunteer", @"Church Group", @"Wardsperson", nil];
onlinetype =[[NSArray alloc]initWithObjects:@"Chatroom", @"Internet Search", nil];
volunteertype =[[NSArray alloc]initWithObjects:@"ABA", @"Hospital Volunteer", @"Church Group", nil];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
switch (component) {
case 0:
return overalltype.count;
break;
case 1:
if (selectedOptionFromColumn1 == 0) {
return healthtype.count;
}
else if (selectedOptionFromColumn1 == 2){
return visitorstype.count;
}
else if (selectedOptionFromColumn1 == 3){
return othertype.count;
}
break;
case 2:
if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 ==0) {
return midwifetype.count;
}
else if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 ==2) {
return doctortype.count;
}
else if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 ==3) {
return otherhealthtype.count;
}
else if (selectedOptionFromColumn1 == 3 && selectedOptionFromColumn2 ==0) {
return onlinetype.count;
}
else if (selectedOptionFromColumn1 == 3 && selectedOptionFromColumn2 ==1) {
return volunteertype.count;
}
break;
default:
break;
}
return 0;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
switch (component) {
case 0:
return [overalltype objectAtIndex:row];
break;
case 1:
if (selectedOptionFromColumn1 == 0) {
return [healthtype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 == 2) {
return [visitorstype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 ==3){
return [othertype objectAtIndex:row];
}
break;
case 2:
if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 == 0) {
return [midwifetype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 == 2) {
return [doctortype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 == 0 && selectedOptionFromColumn2 == 3) {
return [otherhealthtype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 == 3 && selectedOptionFromColumn2 == 0) {
return [onlinetype objectAtIndex:row];
}
else if (selectedOptionFromColumn1 == 3 && selectedOptionFromColumn2 == 1) {
return [volunteertype objectAtIndex:row];
}
break;
default:
break;
}
return 0;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (component) {
case 0:
selectedOptionFromColumn1=[pickerView selectedRowInComponent:0];
[pickerView reloadComponent:1];
_label1.text = [overalltype objectAtIndex: [pickerView selectedRowInComponent:0]];
case 2:
selectedOptionFromColumn2=[pickerView selectedRowInComponent:1];
[pickerView reloadComponent:2];
if(selectedOptionFromColumn1 == 0){
_label2.text = [healthtype objectAtIndex: [pickerView selectedRowInComponent:1]];
}
else if(selectedOptionFromColumn1 ==2){
_label2.text = [visitorstype objectAtIndex: [pickerView selectedRowInComponent:1]];
}
else if(selectedOptionFromColumn1 ==3){
_label2.text = [otherhealthtype objectAtIndex: [pickerView selectedRowInComponent:1]];
}
case 3:
if (selectedOptionFromColumn1 ==0 && selectedOptionFromColumn2 == 0){
_label3.text = [midwifetype objectAtIndex: [pickerView selectedRowInComponent:2]];
}
else if(selectedOptionFromColumn1 ==0 && selectedOptionFromColumn2 ==2){
_label3.text = [doctortype objectAtIndex: [pickerView selectedRowInComponent:2]];
}
else if(selectedOptionFromColumn1 ==0 && selectedOptionFromColumn2 == 3){
_label3.text = [otherhealthtype objectAtIndex: [pickerView selectedRowInComponent:2]];
}
else if(selectedOptionFromColumn1 ==3 && selectedOptionFromColumn2 == 0){
_label3.text = [onlinetype objectAtIndex: [pickerView selectedRowInComponent:2]];
}
else if(selectedOptionFromColumn1 ==3 && selectedOptionFromColumn2 == 1){
_label3.text = [volunteertype objectAtIndex: [pickerView selectedRowInComponent:2]];
}
}
}
- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];
}
@end