In this section, i will guide you to show a pop up viewcontroller just like in attached picture for iPad application. To design a pop up viewcontroller, we are going to use Apple's UIPopoverController class and its delegates. You can use UIViewController or UITableViewController as per your requirement in popup view.
1. In your root .h class
- Include <UIPopoverControllerDelegate>
- @property(nonatomic,retain) UIPopoverController *popOverView;
-(IBAction) showPopupViewController : (id) sender ; // button method from where you want to show pop up
2. In your root .m class
-(IBAction) showPopupViewController : (id) sender{
if ([popOverView isPopoverVisible]) { // check if PopUp already present?
[popOverView dismissPopoverAnimated:YES];
return;
}
if ([popOverView isPopoverVisible]) { // check if PopUp already present?
[popOverView dismissPopoverAnimated:YES];
return;
}
//Now, add a new UIViewController or UITableViewController class to your project which you want to show in pop up, eg : NewTableViewController
NewTableViewController *newDetailView = [[NewTableViewController alloc]initWithNibName:@"NewTableViewController" bundle:nil];
newDetailView.contentSizeForViewInPopover = CGSizeMake(300, 400);
NewTableViewController *newDetailView = [[NewTableViewController alloc]initWithNibName:@"NewTableViewController" bundle:nil];
newDetailView.contentSizeForViewInPopover = CGSizeMake(300, 400);
// Content size gives the actual size of Pop up
//now, creating a UIPopoverViewController
popOverView = [[UIPopoverController alloc] initWithContentViewController:newDetailView];
popOverView.delegate = self;
popOverView = [[UIPopoverController alloc] initWithContentViewController:newDetailView];
popOverView.delegate = self;
// There is a two different method to show pop up view, one is for displaying popup from UIBarButtonItem and another is to show it from customviews (Uibutton,uilabel,uitextfiel,uiview)
/*1. displaying pop up view from UIBarbUttonItems
[popOverView presentPopoverFromBarButtonItem:sender(or give your barbutton objectname)
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popOverView presentPopoverFromBarButtonItem:sender(or give your barbutton objectname)
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
End of displaying popup view from UIBarButtonItem */
/*2. displaying pop up view from custom views[popOverView presentPopoverFromRect:yourCutomViewObj.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
End of displaying popup view from custom views */
}
No comments:
Post a Comment