使用UIPickerView和Label:如何有效地使用它

时间:2015-01-22 19:48:09

标签: ios uipickerview

我正在使用UIPickerView制作应用。 (如下图所示) enter image description here

我想选择课程并让它们显示在上面列出的表格中。棘手的部分是如何根据UIPickerView选择填写标签(列为“填写课程”)。这是我的代码:

- (IBAction)addCourse:(UIButton *)sender {

    NSInteger numRow=[picker selectedRowInComponent:kNumComponent];//0=1st,1=2nd,etc
    NSInteger SeaRow=[picker selectedRowInComponent:kSeaComponent];//0=fall,1=spring,2=summer
    NSInteger CourseRow=[picker selectedRowInComponent:kCourseComponent];

    NSString *num=Number[numRow];
    NSString *season=Season[SeaRow];
    NSString *course=Course[CourseRow];


    NSString *labelName;

    while (i<4) {

    for(row in numRow){
    labelName="_courseLabel"+row +[NSString stringWithFormat:@"%d",i];//labelName to store the labels in the table

            i++;}
    }

}

它有错误,我相信它不是最好的选择,有什么想法可以改进吗?

下面列出了填写其中一个UILabel的示例,但我不知道填写响应表中所有标签的最佳选项。

- (IBAction)addCourse:(UIButton *)sender {

    NSInteger numRow=[picker selectedRowInComponent:kNumComponent];//0=1st,1=2nd,etc
    NSInteger SeaRow=[picker selectedRowInComponent:kSeaComponent];//0=fall,1=spring,2=summer
    NSInteger CourseRow=[picker selectedRowInComponent:kCourseComponent];

    NSString *course=Course[CourseRow];

    NSString *msg=[[NSString alloc ]initWithFormat:@"%@ ",course];
    _courseLabel.text=[msg substringToIndex:8];

}

主要目标:例如,如果在UIPickerView中,选择1st和“CHEM 3511”,则在表格标记为1st的表格中,显示为“要填充的课程”的标签将替换为“CHEM 3511” “,然后用户可以继续从UIPickerView中选择课程并替换响应单元格中的”课程填写“。

0 个答案:

没有答案