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. )
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. )