• UIViewController


    init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)

    其中nibName名称必须与要调用的Interface Builder文件名一致,但不包括文件扩展名,
    比如要使用“aa.xib”,则应写为[[UIViewController alloc] initWithNibName:@”aa” bundle:nil]。
    nibBundle为指定在哪个文件束中搜索指定的nib文件,如在项目主目录下,则可直接使用nil。


    view: UIView! 视图部分

    loadView() 加载视图

    viewDidLoad () view加载完成执行
    isViewLoaded() -> Bool 是否有view部分.

    nibName : String! 视图实例化加载的nib的名字
    nibBundle : NSBundle! 加载的nib所在的文件束
    storyboard :UIStoryboard! 故事版..可以通过该故事版获取,故事版上的内容


    performSegueWithIdentifier(identifier: String!, sender: AnyObject!)
    先谈谈这个Segue,其实就是storyboard里连接两个控制器的那根线。传入Segue的identifier,可在故事板中点击线定义它的名字,实现跳转。
    ps:(跳转后,当前控制器的nextResponder指向跳转之前的控制器)
    segue:在这是用于连接scenes,其有多种类型,包括:Push,Modal,Custom。当然segue也负责传递数据和返回数据。
    整个程序的界面转换就是在各个scene之间切换。界面跳转关系,比如按哪个键跳到哪个界面,是由segue来描述。segue也可以带数据,以便做数据传递。


    shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool
    这个方法用来重写,为跳转时(也就是从一个viewcontroller换到另一个viewcontroller)系统自动调用。传入的identifier参数表示Segue的id。
    默认是返回yes,返回no的话表示不执行跳转。可根据identifier参数设置分支语句,屏蔽相应的跳转。
    1.使用按钮拖动设置的segue有效.也就是说,再下面两种使用中这个方法即使返回false,也并不能阻止执行跳转
    2.调用performSegueWithIdentifier并不会调用该方法,
    3.调用presentViewController并不会调用该方法

    prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!)
    执行跳转的时候,在两个viewcontroller间传数据,segue.destinationViewController目标控制器.segue.sourceViewController 源控制器===self;


    canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController!, withSender sender: AnyObject!) -> Bool
    viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController!, withSender sender: AnyObject!) -> UIViewController!
    segueForUnwindingToViewController(toViewController: UIViewController!, fromViewController: UIViewController!, identifier: String!) -> UIStoryboardSegue!
    UnwindSegue,ios6新增功能,使当前的控制器退出到任意一个控制器。(interface builder中,viewController下,那个绿色的exit)


    顺序:viewControllerForUnwindSegueAction->segueForUnwindingToViewController->unwind

    @IBAction func unwind(seg:UIStoryboardSegue!) {
    println("view controller 1 unwind is called")
    }

    //可以传递参数
    override func viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController!, withSender sender: AnyObject!) -> UIViewController! {

    var result : UIViewController? = nil

    let vc = super.viewControllerForUnwindSegueAction(action, fromViewController: fromViewController, withSender: sender)
    println("(self) returns (vc) from vc for unwind segue")
    result = vc
    return result
    }

    //可以自定义unwinding 的UIStoryboardSegue
    override func segueForUnwindingToViewController(toViewController: UIViewController!, fromViewController: UIViewController!, identifier: String!) -> UIStoryboardSegue! {
    println("(self) was asked for segue")
    return super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier);
    }


    viewWillAppear(animated: Bool) UIViewController对象的视图即将加入窗口时调用;
    viewDidAppear(animated: Bool) UIViewController对象的视图已经加入到窗口时调用;
    viewWillDisappear(animated: Bool) UIViewController对象的视图即将消失、被覆盖或是隐藏时调用;
    viewDidDisappear(animated: Bool) UIViewController对象的视图已经消失、被覆盖或是隐藏时调用;

    override func viewWillAppear(animated: Bool)
    {
    println("viewWillAppear:(self.view.superview)"); //nil
    }

    override func viewDidAppear(animated: Bool)
    {
    println("viewDidAppear:(self.view.superview)"); //parent view
    }

    override func viewWillDisappear(animated: Bool)
    {
    println("viewWillDisappear:(self.view.superview)"); //parent view
    }

    override func viewDidDisappear(animated: Bool)
    {
    println("viewDidDisappear:(self.view.superview)"); //nil
    }


    viewWillLayoutSubviews() 布局发生改变layoutSubviews前调用
    viewDidLayoutSubviews() 布局发生改变layoutSubviews后调用

    title: String! 导航控制器上面的文字,会显示出来

    didReceiveMemoryWarning() 内存警告该怎么办..


    parentViewController: UIViewController! 父控制器
    presentedViewController: UIViewController! 获取到由当前controller调用presentModalViewController展示的子视图。
    presentingViewController: UIViewController! 获取到展示当前controller的父级视图controller。

    iOS5后UIViewController的parentViewController属性已经发生了变化,所有模式model窗口的parentViewController属性都会返回nil,
    要获得模式窗口的父窗口,需要使用新的presentingViewController属性,同时增加的还有presentedViewController属性。
    A调用presentViewController出现B,A的presentedViewController指向B,B的presentingViewController指向A。

    definesPresentationContext
    providesPresentationContextTransitionStyle


    func isBeingPresented() -> Bool 可以判断一个控制器是否由presentingViewController呈现,在viewWillAppear,viewDidAppear中调用。
    func isBeingDismissed() -> Bool 可以判断一个控制器是否由presentingViewController撤销,在viewWillDisappear,viewDidDisappear:中调用。

    func isMovingToParentViewController() -> Bool 判断是否由父视图控制器呈现。
    func isMovingFromParentViewController() -> Bool 判断是否由父视图控制器撤销。

    标准的呈现视图方法,代替 presentModalViewController:animated,如果实现了completion,将会在viewControllerToPresent的viewDidAppear中被调用。
    presentViewController(viewControllerToPresent: UIViewController!, animated flag: Bool, completion: (() -> Void)!)

    关闭视图,退回到上一视图。代替 dismissModalViewControllerAnimated: ,如果实现了completion,将会在该视图控制器的viewDidDisappear:中调用。
    dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)!)


    modalTransitionStyle: UIModalTransitionStyle 用于设置过场动画的类型。
    modalPresentationStyle: UIModalPresentationStyle 这个是要给被呈现的控制器设置才会生效,而不是调用presentViewController的控制器。

    // This controls whether this view controller takes over control of the status bar's appearance when presented non-full screen on another view controller. Defaults to NO.
    var modalPresentationCapturesStatusBarAppearance: Bool

    返回yes,则不能通过resignFirstResponder隐藏键盘,UIModalPresentationFormSheet模式下,要自动隐藏键盘,需要重写这个方法,并返回NO。
    disablesAutomaticKeyboardDismissal() -> Bool

    // Deprecated in 7_0, Replaced by the following:

    var edgesForExtendedLayout: UIRectEdge // Defaults to UIRectEdgeAll
    var extendedLayoutIncludesOpaqueBars: Bool // Defaults to NO, but bars are translucent by default on 7_0.
    var automaticallyAdjustsScrollViewInsets: Bool // Defaults to YES

    /* The preferredContentSize is used for any container laying out a child view controller.
    */
    var preferredContentSize: CGSize

    // These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.
    func preferredStatusBarStyle() -> UIStatusBarStyle // Defaults to UIStatusBarStyleDefault
    func prefersStatusBarHidden() -> Bool // Defaults to NO
    // Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
    func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation // Defaults to UIStatusBarAnimationFade

    // This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.
    func setNeedsStatusBarAppearanceUpdate()

    /* This method returns either itself or the nearest ancestor that responds to the action. View controllers can return NO from canPerformAction:withSender: to opt out of being a target for a given action. */
    func targetViewControllerForAction(action: Selector, sender: AnyObject!) -> UIViewController!

    /* This method will show a view controller appropriately for the current size-class environment. It's implementation calls
    `[self targetViewControllerForAction:sender:]` first and redirects accordingly if the return value is not `self`, otherwise it will present the vc. */
    func showViewController(vc: UIViewController!, sender: AnyObject!)

    /* This method will show a view controller within the semantic "detail" UI associated with the current size-class environment. It's implementation calls `[self targetViewControllerForAction:sender:]` first and redirects accordingly if the return value is not `self`, otherwise it will present the vc. */
    func showDetailViewController(vc: UIViewController!, sender: AnyObject!)

  • 相关阅读:
    Spark&Hive结合起来
    spark&dataframe
    JAVA-数组或集合
    九种经典排序算法详解(冒泡排序,插入排序,选择排序,快速排序,归并排序,堆排序,计数排序,桶排序,基数排序)
    B+树介绍
    @transactional注解在什么情况下会失效,为什么。
    一个ArrayList在循环过程中删除,会不会出问题,为什么?
    Java:传值还是传引用?
    Java序列化的方式。
    实现动态代理的两种方式
  • 原文地址:https://www.cnblogs.com/zhepama/p/3908620.html
Copyright © 2020-2023  润新知