2

How to include uibutton in WEpopover controller ,I want a set of 3 buttons in WEpopover,On click navigates to other view.Where should i change in WEpopover controller?

Fazil
  • 1,390
  • 2
  • 13
  • 26
  • `-viewDidLoad` is the most common place to set up programmatic UI hierarchies. – CodaFi Nov 12 '12 at 06:29
  • @CodaFi But where it will be include in the popover controller.when i click – Fazil Nov 12 '12 at 06:31
  • So, let me clarify something first: You have a popover with three buttons set up already, but now you want to push a new view into the popover when the buttons are clicked? – CodaFi Nov 12 '12 at 06:32
  • My doubt is how can i include three buttons in WEpopover controller @CodaFi – Fazil Nov 12 '12 at 06:34
  • Ah! I see. Perhaps you should read up on [view controllers](http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html) and [view hierarchies](http://stackoverflow.com/questions/4820094/programmatically-creating-views-in-ios-how-does-it-work) then. It's a trivial task to add subviews to a view in iOS. – CodaFi Nov 12 '12 at 06:38

1 Answers1

1

Underneath the hood, WEPopover works by adding a subview, a 'container', to the mainWindow, which is a subclass of UIView that is at the very root of your hierarchy of views[1]. To that container, it adds the view property of a given view controller. To know how to size that view, it asks the view controller for its contentSizeForViewInPopover.

Because of this, the way you setup your 3 buttons is the same way you would setup 3 buttons for any other view controller. The only difference is that in your UIViewController subclass that handles the 3 buttons, you need to set your contentSizeForViewInPopover.

You can set this property in init or viewDidLoad. (Remember to add it to the correct init method -- if e.g. you're making this view controller in a storyboard, init will not be called but instead initWithCoder:).

To actually add the buttons, you would probably want some code like this in viewDidLoad:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

[1] If you asked a view for its superview, and then asked THAT view for its superview, and so on, you would eventually reach the mainWindow.

MaxGabriel
  • 7,617
  • 4
  • 35
  • 82
  • 1
    -init would be best, but they both work. – CodaFi Nov 12 '12 at 06:40
  • Two things here that are nagging me: 1) The container is not a UIView, it's a UIWindow. 2) The OP seems a bit of a novice, perhaps you could explain what the way to set up the buttons would be (a little pseudo-code never hurt nobody). +1 anyhow. – CodaFi Nov 12 '12 at 06:46
  • CodaFi, in the implementation of WEPopover I'm currently using, the WEPopoverContainerView is a subclass of UIView. But I was saying that the window is literally `aKindOfClass` of `UIView` because I think that makes the concept of a window relatable. I'll clarify that it's a subclass in the post and add some sample code. – MaxGabriel Nov 12 '12 at 08:30