Monday, February 3, 2014

Working with UIPopOverControllers


Hi, I have been using them since popover feature was introduced.

I would like to show a small sample for those whom popover fascinates..

Hope you all find it simplest and helpful to..

Lets start.....

1) Create a Simple View based Application as a start project.

I created like this : 



2) Add files namely  : 

PopOverViewController.h
PopOverViewController.m
PopOverViewController.xib

DataViewController.h
DataViewController.m
DataViewController.xib


3) Lets start with file PopOverViewController.xib

Add a UIButton on iPad UI showing text "Show PopOver"
Link this button with an IBAction named - (IBAction)showPopOver:(id)sender

4) Moving towards PopOverViewController.m

 Firstly create a private property like this : 



Secondly Perform Action on the IBAction as : 


Explanation : 
  • DataViewController is another controller with some UI components placed on its XIB.
  • The IBActions are handled accordingly.

  • We set the preferredContentSize property so that we can define the bounds of the popover being displayed.

  • self.popOverController is the private property we created in the .m file. 
  • This helps in presenting the DataController's view inside a popOver.

List of permitted Arrow Directions:


    UIPopoverArrowDirectionUp = 0,
    UIPopoverArrowDirectionDown = 1,
    UIPopoverArrowDirectionLeft =  2,
    UIPopoverArrowDirectionRight = 3,
    UIPopoverArrowDirectionAny = UIPopoverArrowDirectionUp
                                                          UIPopoverArrowDirectionDown
                                                          UIPopoverArrowDirectionLeft
                                                          UIPopoverArrowDirectionRight,
    UIPopoverArrowDirectionUnknown = NSUIntegerMax


5) Now moving towards DataViewController.h



6) UI Designing on DataViewController.xib

I added a label and 2 buttons which are associated with IBActions respectively.


7) Handling button clicks on DataViewController.m





Both the View Controllers are ready, now run the app and see the work..

One important thing for Orientation change



Whenever orientation change creates problem for popover presentation , remember to present popover again @ orientation did change selector.
      
        

Hope all are able to get help from this.
:)

No comments:

Post a Comment