行动表上的uipickerview实施

时间:2011-09-05 11:37:47

标签: iphone

我已在操作表上实现了UIPicker视图概念,它工作正常,但有一点是它没有正确显示行索引。选择器视图中没有突出显示的行。enter image description here

我上传了图片。请给我解决方案。

以下是我正在使用的代码:

-(IBAction)clickformedtype:(id)sender
    {
        UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Select medication type" delegate:self
                                                   cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];
        [asheet showInView:[self.view superview]]; //note: in most cases this would be just self.view, but because I was doing this in a tabBar Application, I use the superview.
        [asheet setFrame:CGRectMake(0, 117, 320, 383)];
        [asheet release];
    }


    -(void)willPresentActionSheet:(UIActionSheet *)actionSheet {

        medicationtypepicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
        medicationtypepicker.delegate = self;
        medicinetypearray = [[NSMutableArray alloc]initWithObjects:@"ml",@"capsules",@"eyedrops", nil];

        //medicationtypepicker = [[NSMutableArray alloc]initWithObjects:@"ml",@"capsules",@"eyedrops", nil];
        //medicationtypepicker.datePickerMode = ui;

        //Configure picker...
        // [medicationtypepicker setMinuteInterval:1];

        [medicationtypepicker setTag: kDatePickerTag];

        //Add picker to action sheet
        [actionSheet addSubview:medicationtypepicker];

        // [medicationtypepicker release];

        //Gets an array af all of the subviews of our actionSheet
        NSArray *subviews = [actionSheet subviews];

        [[subviews objectAtIndex:SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)]; 
        [[subviews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];


    }


    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
    UIPickerView

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
        return [medicinetypearray count];
    }

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
    {
        return [medicinetypearray objectAtIndex:row];
    }

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        medicinetype.text=[medicinetypearray objectAtIndex:row];
        //medicationtypepicker.hidden = YES;

    }

提前致谢。

2 个答案:

答案 0 :(得分:3)

UIPickerView有一个名为“showsSelectionIndicator”的属性 - 将此设置为YES也将autoresizingMask设置为UIViewAutoresizingFlexibleWidth,如下所示...

    mTimePicker.showsSelectionIndicator = YES;          
    mTimePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;

答案 1 :(得分:2)

尝试将属性showsSelectionIndicator设置为YES

medicationtypepicker.showsSelectionIndicator = YES;