Two picker views in the same UIViewController - iphone

I have a UIViewController that contains two picker views. For some reason when I run the project one picker view is overshadowing the other. How can I set the positions, height and other parameters in code?

Why are you using two picker view ? You can change the content of the pickerview when needed.
Even if u want to use two of them, the picker would be at the bottom anyways. Use show and hide property of the pickerview to handle your required task

You have to implement -initWithFrame: method (assuming that you're instantiating the view in code). Here's an example showing to picker views -
UIPickerView *myPickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
[self.view addSubview:myPickerView1];
UIPickerView *myPickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 320)];
[self.view addSubview:myPickerView2];
If you see this image below, they are not overshadowing one another. I hope this easy explanation helps. Welcome to iOS Development!

you can do this way
//first picker
optionPicker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 200)];
[self.view addSubview:optionPicker1];
//second picker
optionPicker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
[self.view addSubview:optionPicker2];

Related

Side sliding tabs in iPhone/iPad application

Is it possible to create a side sliding tabs (like the menu in WP7; I'm not sure what the correct term is) for iPhone/iPad applications? I haven't implemented any code yet, right now I'm assuming that it could probably be done with multiple vertical UIScrollViews within a horizontal UIScrollView.
I've seen this kind of menu in iPad applications (Discovr Music/Movies), and would like to implement it in iPhone if it is possible. Also, is this kind of menu against any of Apple's UX policies?
Thanks!
This is possible and you can do it.
For example:
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 460)];
UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[wrapper addSubview:subView1];
UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];
[wrapper addSubview:subView2];
[scrollView setContentSize:wrapper.frame.size];
[scrollView setPagingEnabled:YES]; //Here's what you want to do!
[scrollView addSubview:wrapper];
Didn't test the code, but it should work.
Important is to add Subview to the ScrollView. (It would also work if you don't use a wrapper, but I often use it, because of the size.)

How to add a view on button click without using interface builder

I just did it like this
-(IBAction)clickButtonPressed:(id)sender
{
NSLog(#"Clicked.........");
UIView *showView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:showView];
}
This action called & There were no any error coming but this view is also not shown.
Try setting the view's background color to make sure that it is not actually added without you noticing, also release your view after adding it (if you are not using ARC)
-(IBAction)clickButtonPressed:(id)sender {
NSLog(#"Clicked.........");
UIView *showView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
showView.backgroundColor = [UIColor blackColor];
[self.view addSubview:showView];
[showView release]; // if not ARC
}

iPad UIPickerView causing problems

Can someone show me how I can get a UIPickerView working on the iPad? I'm trying to have a UIPickerView in the middle of the screen. Here is the current code I have:
if(IDIOM == IPAD)
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(200, 345, 400, 216)];
else
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 245, 0, 0)];
namePickerView.delegate = self;
namePickerView.showsSelectionIndicator = YES;
So this just puts the picker view on the far left. On the iPhone, everything is perfect. But on the iPad, this doesn't work. As soon as I try to scroll through the values, nothing movies. The UIPickerView does not respond to any touches. What is the issue here? I just want to put a UIPickerView of default size in the middle of my iPad screen, 345 pixels down.
UIPickerViews on the ipad don't have a default size (ie width).
change
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 0, 0)];
to
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 400, 216)];

iPad - How to move Mulitple UIViews side-by-side

How to move multiple UIViews Side-by-Side just like an twitter application working in iPad. With full of effects animation and rotations.
You should take a look at the UIScrollView with paging enabled.
Make all your views and put them next to one another inside a UIScrollView. i.e.
// Get your views
MyView *v1 = [[[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
MyView *v2 = [[[MyView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)] autorelease];
MyView *v3 = [[[MyView alloc] initWithFrame:CGRectMake(640, 0, 320, 480)] autorelease];
// Make the UIScrollView
UIScrollView *scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[scroll setPagingEnabled:YES];
[[scroll addSubview:v1];
[[scroll addSubview:v2];
[[scroll addSubview:v3];
[scroll setContentSize:CGSizeMake(960, 480)];
// add the scroll view to your view
[[self view] addSubview:scroll];
Now, the three views (v1, v2 and v3) are next to each other in a scroll view whose content is much wider the view. With paging enabled, they will scroll left and right but won't stop halfway through a view.
Take a look at view animations:
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone

can i make the searchbar static in iphone application

I want that searchbar should also scroll with scrolling mean when i scroll down searchbar should be visible.
as there anyway to do so...
thanks. and sorry for my bad english..
If I understand you correctly, this is what you should do:
Open up the interface builder and make the SearchBar the child of the table view if you want it to scroll along with the contents. If you need it to be always visible, drag it out of the tableview.
Well you can also simply do that
SearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(10, 5, 300, 50)];
SearchBar.tintColor=[UIColor blackColor];
[SearchBar setDelegate:self];
//[self.view addSubview:search];
table=[[UITableView alloc]initWithFrame:CGRectMake(0, 15, 320, 480) style:UITableViewStyleGrouped];
table.delegate=self;
table.dataSource=self;
table.backgroundColor=[UIColor darkGrayColor];
table.tableHeaderView=SearchBar;
[self.view addSubview:table];