Reputation: 2096
I have a View
(CupsViewController
) with a Label
and when it's clicked, TableView
(AddressTableController
) slides from the bottom of the screen and stays in the lower half.
In TableView
, when Ok Button
is pressed, I want to change value of Label
and remove TableView
with animation (that is, slide to the bottom).
Here is my code:
CupsViewController
Method called when click on Label
- (IBAction)showPop:(id)sender
{
addressTableController = [[AddressTableController alloc]initWithStyle:UITableViewStyleGrouped];
[addressTableController setDelegate:self];
[[self view] addSubview:[addressTableController myTableView]];
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[[addressTableController myTableView] setFrame:CGRectMake(0, kScreenHeight * 0.5, kScreenWidth, kScreenHeight * 0.5)];
} completion:nil];
}
Method called from AddressTableController
when Button
is pressed
- (void)addressTableController:(AddressTableController *)viewController didChooseValue:(int)value {
direccionLabel.text = [[[[myAppDelegate usuarioActual] cups] objectAtIndex:value] direccion];
[addressTableController.view removeFromSuperview];
}
Image
As you can see, I've tried with removeFromSuperview
but it does nothing. How can I slide TableView
to the bottom?
Upvotes: 0
Views: 2818
Reputation: 2044
It seems that you myTableView
property returns a different view, not the one that is referenced in the view
property. So you basically add the former as a subview ([[self view] addSubview:[addressTableController myTableView]];
), but try to remove the latter ([addressTableController.view removeFromSuperview];
).
Just do
[[addressTableController myTableView] removeFromSuperview];
instead of
[addressTableController.view removeFromSuperview];
Here you go. Cheers, mate! :)
P.S. if you want to animate the view out, you can do it like this
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
// animation code...
} completion:^(BOOL finished) {
[[addressTableController myTableView] removeFromSuperview];
}];
Upvotes: 1