user198725878
user198725878

Reputation: 6386

UIToolbar is not shown

Please find the below code i tried to add toolbar into the uipicker but it is not working

Pls let me know

    UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
[pickerViewCountry sizeToFit];
pickerViewCountry.frame = CGRectMake(0,210 , 320, 15);
[self.view addSubview:pickerViewCountry];

//[pickerViewCountry release];

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(10,200, 320, 44);
toolbar.barStyle = UIBarStyleBlackTranslucent;
[pickerViewCountry addSubview:toolbar];
[toolbar release];

Upvotes: 0

Views: 350

Answers (3)

Satya
Satya

Reputation: 3330

You can do different things to solve that issue.

  1. add the toolbar to self.view and set frame above the picker

  2. Change the toolbar frame as toolbar.frame = CGRectMake(10,-44, 320, 44);

Upvotes: 0

johnluttig
johnluttig

Reputation: 740

When you call:

toolbar.frame = CGRectMake(10,200, 320, 44);

The CGRect is relative to the picker view (if you addSubview to pickerViewCountry), so the placement would not align at the top of the picker view, but rather somewhere in the lower right corner outside of the picker view, so it wouldn't display.

What are you trying to accomplish? You might not want to add a UIToolbar to a UIPickerView. You could instead try adding the UIToolbar to the main view.

[self.view addSubview: toolbar];

and keep toolbar.frame = CGRectMake(10,200, 320, 44); as it is.

Upvotes: 2

Kinetic Stack
Kinetic Stack

Reputation: 798

Since you are adding the toolbar as a subview, I believe that the X and Y coordinates of the CGRectMake will be relative to the pickerViewCountry frame. Try setting the following line:

toolbar.frame = CGRectMake(10,200, 320, 44);

to this one:

toolbar.frame = CGRectMake(0,0, 320, 44);

I have not tried it, so I am not sure yet if this is actually the case. I will try it out and let you know if no one else has responded by then.

Upvotes: 0

Related Questions