Reputation: 1257
I want to back to main view from popover view here i explain you
-(void)tapAction1:(UITapGestureRecognizer*) sender
{
Clicked = sender.view.tag-500;
DemoViewController *sign = [[DemoViewController alloc]initWithNibName:@"DemoViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 100, sign.view.frame.size.height)];
popoverView.backgroundColor = [UIColor clearColor];
popoverContent.view = popoverView;
[popoverView addSubview: sign.view];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake( sign.view.frame.size.width, sign.view.frame.size.height);
//create a popover controller
UIPopoverController* popover = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[sender.view frame]
fromView:[sender.view superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 500);
popoverRect.origin.x = popoverRect.origin.x;
//popoverRect.size.height = ;
//present the popover view non-modal with a
//refrence to the toolbar button which was pressed
[popover presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
//[[self view] addSubview:sign.view];
[UIView commitAnimations];
}
Now in demoviewcontroller is one xib. In which i want to put one button named close and i want to close this popover.
Upvotes: 1
Views: 252
Reputation: 38259
Add button in DemoViewController like this:
UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnClose addFrame:CGRectMake(20,20,80,30)];
[btnClose setTitle:@"Close" forState:UIControlStateNormal];
[btnClose addTarget:self action:@selector(dissmissPopOver:) forControlEvents:UIControlEventTouchUpInside];
[sign addSubView:btnClose];
Now selector is:
- (void)dissmissPopOver:(id)sender
{
[popover dismissPopoverAnimated:YES];
}
Upvotes: 1
Reputation: 1503
I would make the UIPopoverController* popover
an property in DemoViewController
.
@property (nonatomic, strong) UIPopoverController* popover;
Then you can pass the popover, allocated in the code you have posted, to this class:
sign.popover = popover;
Add this selector to DemoViewController
- (IBAction) didClickDismissPopoverButton:(id)sender
{
[self.popover dismissPopoverAnimated:YES];
}
and then just connect this IBAction with UIButton Touch Up Inside event in Interface Builder.
Upvotes: 1