UIViewController (popover view controller)

UIViewController
1. You should not use multiple custom view controllers to manage different portions of
   the same view hierachy. Similary, you should not use a single custome view controller
   object to manage multiple screens worth of content.
2. Any view controller object can present any other view controller object modally.

(You use the @dynamic statement to tell the compiler to suppress a warning if it can’t find an implementation of accessor methods specified by an @property declaration.)

---两种情况使用View Contoller
1. 分离式
2. 集成式

---显示view controller programmatically
-(void) displayModalView
{
    MyViewController *vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil] autorelease];
    [self presentModalViewController:vc animated:YES];
}

---利用Interface Builder 创建UIView 或者 UIViewController (参考Simple View Template of XCode)

---利用代码创建View

- (void)loadView {
    self.wantsFullScreenLayout = YES;
    MetronomeView *view = [[MetronomeView alloc]
                           initWithFrame:[UIScreen mainScreen].applicationFrame];
    view.metronomeViewController = self;
    self.view = view;
    self.metronomeView = view;
    [view release];
}

(Note: When overriding the loadView method to create your views programmatically, you should not call super.)

Popover:
1. The advantage of popovers is that they do not cover the entire screen and can be dismissed by simply tapping outside the popover view.
2. How to create and present popover view
   >> Create an instance of the UIPopoverController class and initialize it with your view controller object.
   >> Specify the size of the popover, which you can do in one of two ways:
      contentSizeForViewInPopover (default size: 320 pixels wide by 1100 pixels high)
      popoverContentSize
   >> (Optional) Assign a delegate to the popover. For more information about the responsibilities of the delegate
   >> Present the popover.
      presentPopoverFromBarButtonItem:permittedArrowDirections:animated: (if toolbar is presented)
      presentPopoverFromRect:inView:permittedArrowDirections:animated:
      (setPopoverContentSize:animated: runtime change size)
      
- (IBAction)toolbarItemTapped:(id)sender
{
   MyCustomViewController* content = [[MyCustomViewController alloc] init];
   UIPopoverController* aPopover = [[UIPopoverController alloc]
        initWithContentViewController:content];
   aPopover.delegate = self;
   [content release];

   // Store the popover in a custom property for later use.
   self.popoverController = aPopover;
   [aPopover release];
   [self.popoverController presentPopoverFromBarButtonItem:sender
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
    for popover view, if click outside of the view, the popview will dismiss, if you want to do it programically with:
    dismissPopoverAnimated:
    
    Popover Delegate
    The popoverControllerShouldDismissPopover: delegate method lets you control whether the popover should actually be dismissed.
    popoverControllerDidDismissPopover:your implementation returns YES in popoverControllerShouldDismissPopover, the controller dismisses the popover and sends
    (By the time the popoverControllerDidDismissPopover: method of your delegate is called, the popover itself has been removed from the screen. At this point, it is safe to release the popover controller if you do not plan to use it again. )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值