2012年7月12日 星期四

View Controllers(一)

從蘋果網站挖出圖來參考

image: Art/intro.png














Creating a chain of modal view controllers







UISplitViewController

參考史丹福教材

The UISplitViewController class is a container view controller that manages two panes of information. The first pane has a fixed width of 320 points and a height that matches the visible window height. The second pane fills the remaining space.

A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window. The panes of your split view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface. Split view controllers cannot be presented modally.

UISplitViewController的四種可能狀態

 1. 垂直分離(popover)

2. 垂直合併



3. 水平分離(popover)















4. 水平合併













1. Just drag one out into an iPad Storyboard (only)
If you don’t see a Split View Controller in the Object Library, your storyboard is not iPad-style.
You select which style of storyboard you have when you first create it (via New File ... menu item).

2. Split view is a base UI element only
It only makes sense for the Split View to be the initial view controller of your application.
You would (probably) never embed one in another view controller.
You would only ever have one split view controller in your application.

3. Setting/Getting the two view controllers  
 Both view controllers are almost always set with ctrl-drag in Xcode.
@property (nonatomic, copy) NSArray *viewControllers; // 0 is left (master), 1 is right (detail)
It doesn’t really make sense for this array to have anything but 2 UIViewControllers in it.
Note that this is not a readonly @property.
But also note that it forces you to set/get the both at the same time.
It is copy so that you don’t pass a mutable array and then try to modify it afterwards.

The delegate controls the split view’s visual appearance
@property (nonatomic, assign) id <UISplitViewControllerDelegate> delegate;
The right side is always visible in a split view (we call it the “detail” view of the split view).
The split view’s delegate is asked about when the left side (the “master”) should be on screen.
When the left side is not on screen, you are responsible for displaying a UIBarButtonItem to show it (you will be provided with a UIBarButtonItem to use in as an argument to the delegate method).

Notice assign pointer type.  Should probably be weak.  assign means weak without auto-zeroing.
This means you can get a dangling pointer (though, in practice, this is unlikely in this case).

根據上面四種水平垂直的顯示狀態,有下面三種設定方式。

1. Always hide left side behind a bar button (參考圖1/3)- (BOOL)splitViewController:(UISplitViewController *)sender
   shouldHideViewController:(UIViewController *)master
              inOrientation:(UIInterfaceOrientation)orientation
{
    return YES; // always hide it
}

2. Never hide left side behind a bar button (參考圖2/4)
- (BOOL)splitViewController:(UISplitViewController *)sender
   shouldHideViewController:(UIViewController *)master
              inOrientation:(UIInterfaceOrientation)orientation
{
    return NO; // never hide it
}

3. Hide it in portrait orientation only(參考圖1/4)
- (BOOL)splitViewController:(UISplitViewController *)sender
   shouldHideViewController:(UIViewController *)master
              inOrientation:(UIInterfaceOrientation)orientation
{
    return UIInterfaceOrientationIsPortrait(orientation);
}


第三種方法要特別注意UISplitViewControllerDelegate
 如果沒有設好BarButton,則可能會有下圖的狀況,無法顯示popover


UISplitViewControllerDelegate
Handling the bar button item ...
This gets called in your delegate when the master gets hidden.
- (void)splitViewController:(UISplitViewController *)sender
     willHideViewController:(UIViewController *)master
          withBarButtonItem:(UIBarButtonItem *)barButtonItem
       forPopoverController:(UIPopoverController *)popover
{
    barButtonItem.title = @“Master”; // use a better word than “Master”!
    // setSplitViewBarButtonItem: must put the bar button somewhere on screen
    // probably in a UIToolbar or a UINavigationBar
    [detailViewController setSplitViewBarButtonItem:barButtonItem];
}

When it is time for the bar button to go away ...
- (void)splitViewController:(UISplitViewController *)sender
     willShowViewController:(UIViewController *)master
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // removeSplitViewBarButtonItem: must remove the bar button from its toolbar
    [detailViewController removeSplitViewBarButtonItem:nil];
}

2012年7月9日 星期一

Segues連結變數需注意處



在練習psychologist時,Outlets處要注意連接,參考史丹福課程第六節54min處