tags:

views:

116

answers:

2

alt text

In the figure, what you see in "red" is another view that slides up once you click the first + button. This "red" view does not have a separate view controller. On every "+" button click, I want this view to slide up with a different element embedded in it. For instance, on the first "+" button click , I would like this red view to slide up with a datepicker embedded in it. On second "+" button click, I would like this red view to slide up with a UIPicker View embedded in it. I have the elements: UIDatepicker and UIPicker prepared. I don't know when and where to embed them and what should be their frame size.

I am initializing the "red" view in the viewDidLoad method

viewDidLoad {

CGRect frame=CGRectMake(0, CGRectGetMaxY(self.view.bounds)-70, 320, 150);

popup=[[UIView alloc]init];

popup.backgroundColor=[UIColor redColor];

[popup setFrame:frame];

}

and I am sliding it up in

-(void) btnClick:(id)sender { frame=CGRectMake(0, 240, 320, 150);

[UIView beginAnimations:nil context:nil];

    [popup setFrame:frame];

[UIView commitAnimations];  

}

A: 

You should not modify the popup hierarchy everytime you click on a + button. Create as many popup as you need and show the appropriate popup when you need it, it will allows you to easely swicth from one popup to another at the same time :

[UIView beginAnimations:nil context:nil];
currentlyOpenPopup.frame = CGRectMake(0.0, self.bounds.size.height, 320,150);
currentlyOpenPopup = DatePickerPopup //here comes the if blablabl set the right popup to show;
currentlyOpenPopup.frame = CGRectMake(0.0, self.bounds.size.height-150, 320, 150);
[UIView commitAnimations]; 

Create your popups in ViewDidLoad for example:

datePickerPopup = [[UIView alloc] initWithFrame:CGRectFrame(0,0,320,150)];
UIDatePicker* dp = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,0,320,216)];
[datePickerPopup addSubView:dp];
[dp release];

the UIView is there only if you need to place multiple object on one popup.

VdesmedT
Hey I couldn't understand your answer properly. How do I add different elements to the same popup(view) depending on the button click. What should I set as the frame for my various elements (datepicker, pickerView etc). In the viewDidLoad method, I have added the pop view at the very last after everything else.
Bogus Boy
"ow do I add different elements to the same popup(view)" : You don't ! Create multiple popUp for every input type.
VdesmedT
A: 

Add all the code for the datepicker and regular picker as you normally would.

When a button is pressed add the picker/datepicker to popup.

picker = [[UIPickerView alloc] init];
picker.frame = CGRectMake(0,0,picker.frame.size.width,picker.frame.size.height);
[popup addSubview:picker];

//your code:
[UIView beginAnimations:nil context:nil];
[popup setFrame:frame];
[UIView commitAnimations];

when hiding the popup view add:

  [UIView setAnimationDelegate:self];
  [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context::)];

Add a method:

- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context 

Remove the pickerView or whatever you added in that method..

Larsaronen
Hey my problem is how, where and when to add the UIDatePicker to the popup view?
Bogus Boy
What do you mean? Did you try my code and it did'nt work?
Larsaronen
@ larsaronen Thanks a ton buddy, really grateful to you for the help extended. I was struggling since morning to accomplish this, finally it comes through larsaronen. If you got time, can you also check the other question that I have posted here:http://stackoverflow.com/questions/3618126/uitableview-uitabbar
Bogus Boy
Glad i could help!
Larsaronen