开发者

Problem in showing subview as popover

I want to show the subview of a view in popover. To elaborate,

I have a mainViewController. I hava a subview 'songListView' in this mainViewController. I have a button titled 'list' in the mainViewController' itself. I want to show the songListView in popover o开发者_JAVA百科n clicking the button 'list'.

So, how should I do this.


You could use the below code as a reference for showing PopOver from a UIButton

-(void) buttonAction:(id)sender {
   //build our custom popover view
   UIViewController* popoverContent = [[UIViewController alloc]
                  init];
   UIView* popoverView = [[UIView alloc]
                  initWithFrame:CGRectMake(0, 0, 200, 300)];
   popoverView.backgroundColor = [UIColor greenColor];
   popoverContent.view = popoverView;

   //resize the popover view shown
   //in the current view to the view's size
   popoverContent.contentSizeForViewInPopover =
                  CGSizeMake(200, 300);

   //create a popover controller
   self.popoverController = [[UIPopoverController alloc]
               initWithContentViewController:popoverContent];

   //present the popover view non-modal with a
   //refrence to the button pressed within the current view
   [self.popoverController presentPopoverFromRect:popoverButton.frame
               inView:self.view
               permittedArrowDirections:UIPopoverArrowDirectionAny
               animated:YES];

   //release the popover content
   [popoverView release];
   [popoverContent release];
}


My problem is solved. I just created another View Controller class, i.e. 'TempPopoverView'.

Then I set the view of this TempPopoverView equal to the subview of my MainView

Here is the code snippet from my code:

TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:@"TempPopoverView" bundle:nil];

[self. songListView setHidden:NO];//songListView is subview of MainView
 viewController.view=self. songListView;
 UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
 navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];

[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
 [navCont release];


U can use presentModalViewController on your main view.

For example

SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];

There are different animations possible as well.


as simple as you think to add subview in self.view

[popoverController.contentViewController.view addSubview:yourselfobject];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜