UIPickerview не отображается в правильной позиции

Извините за такой глупый вопрос, но я не знаю, почему мой UIPickerView с кнопкой «Готово» не появляется в нужном месте. Я использую следующий код, но я не знаю, почему у меня возникает такая проблема.

actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];


UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,320,40)];

[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonTapped:)];
[barItems addObject:cancelBtn];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped:)];
[barItems addObject:doneBtn];

[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];


//-----------
maritalStatusPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
maritalStatusPickerView.delegate = self;
maritalStatusPickerView.showsSelectionIndicator = YES;


[actionSheet addSubview:maritalStatusPickerView];

[actionSheet showInView:self];

введите здесь описание изображения


person Vaibhav Gautam    schedule 13.03.2013    source источник
comment
Ваше изображение неправильно понимается, пожалуйста, опубликуйте полный снимок экрана.   -  person 08442    schedule 13.03.2013


Ответы (4)


используйте приведенный ниже код

actionSheet=[[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.frame = CGRectMake(0, 234, 320, 256);

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,320,40)];

[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonTapped:)];
[barItems addObject:cancelBtn];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped:)];
[barItems addObject:doneBtn];

[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];


//-----------
maritalStatusPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
maritalStatusPickerView.delegate = self;
maritalStatusPickerView.showsSelectionIndicator = YES;
//        [self addSubview:maritalStatusPickerView];

[actionSheet addSubview:maritalStatusPickerView];

[self.view addSubview:actionSheet];
person Pratik    schedule 13.03.2013

Почему вы добавляете maritalStatusPickerView 2 раза

[self addSubview:maritalStatusPickerView];

[actionSheet addSubview:maritalStatusPickerView];
person arun.s    schedule 13.03.2013
comment
это было добавлено по ошибке, но даже после удаления это не работает - person Vaibhav Gautam; 13.03.2013

Просто включите рамку листа действий в свой код после инициализации.

actionSheet.frame = CGRectMake(0, 0, 320, 256);

обратитесь к этому вопросу

person Lithu T.V    schedule 13.03.2013

вам нужно добавить свой лист действий в свое представление и изменить координату, если вы хотите открыть окно выбора из нижней части представления.

[actionSheet addSubview:maritalStatusPickerView];

//Replace this :  [actionSheet showInView:self];

[self.view addSubview:actionSheet];
person Dhruvik    schedule 13.03.2013