GVKun编程网logo

从后台打开应用程序时不调用 ViewDidAppear

3

在本文中,我们将带你了解从后台打开应用程序时不调用ViewDidAppear在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的-viewDidLoad和-viewWillApear和-vie

在本文中,我们将带你了解从后台打开应用程序时不调用 ViewDidAppear在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的- viewDidLoad 和 - viewWillApear 和 -viewDidAppear、-viewWillAppear:和 -viewDidAppear:区别、asp.net – RadGrid在Visual Studio 2013中打开应用程序时,在不同的100%相同应用程序中进行渲染、iOS viewWillDisappear viewWillAppear viewDidAppear等

本文目录一览:

从后台打开应用程序时不调用 ViewDidAppear

从后台打开应用程序时不调用 ViewDidAppear

我有一个视图控制器,其中我的值为
0(标签),当我从另一个视图控制器打开该视图控制器时,ViewController我已将viewDidAppear标签上的值设置为
20。它工作正常,但是当我关闭我的应用程序并再次打开我的应用程序但值没有改变viewDidLoad,因为没有任何viewDidAppear东西viewWillAppear被调用。打开我的应用程序时如何拨打电话。我必须做任何事情applicationDidBecomeActive吗?

答案1

小编典典

对事件的确切顺序感到好奇,我按如下方式检测了一个应用程序:(@Zohaib,您可以使用下面的 NSNotificationCenter
代码来回答您的问题)。

// AppDelegate.m- (void)applicationWillEnterForeground:(UIApplication *)application{    NSLog(@"app will enter foreground");}- (void)applicationDidBecomeActive:(UIApplication *)application{    NSLog(@"app did become active");}// ViewController.m- (void)viewDidLoad{    [super viewDidLoad];    NSLog(@"view did load");    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];}- (void)appDidBecomeActive:(NSNotification *)notification {    NSLog(@"did become active notification");}- (void)appWillEnterForeground:(NSNotification *)notification {    NSLog(@"will enter foreground notification");}- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    NSLog(@"view will appear");}- (void)viewDidAppear:(BOOL)animated {    [super viewDidAppear:animated];    NSLog(@"view did appear");}

启动时,输出如下所示:

2013-04-07 09:31:06.505 myapp[15459:11303] view did load2013-04-07 09:31:06.507 myapp[15459:11303] view will appear2013-04-07 09:31:06.511 myapp[15459:11303] app did become active2013-04-07 09:31:06.512 myapp[15459:11303] did become active notification2013-04-07 09:31:06.517 myapp[15459:11303] view did appear

进入后台,然后重新进入前台:

2013-04-07 09:32:05.923 myapp[15459:11303] app will enter foreground2013-04-07 09:32:05.924 myapp[15459:11303] will enter foreground notification2013-04-07 09:32:05.925 myapp[15459:11303] app did become active2013-04-07 09:32:05.926 myapp[15459:11303] did become active notification

- viewDidLoad 和 - viewWillApear 和 -viewDidAppear

- viewDidLoad 和 - viewWillApear 和 -viewDidAppear

目录:[ - ]

  • Discussion
  • - (void)viewDidAppear:(BOOL) animated 该方法通知视图控制器,它的视图已经被加入视图树 Discussion 我们可以重写该方法执行附加任务,实现如何显示出视图。重写必须调用 super 方法。 Note: If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed.
  • 该方法通知视图控制器,它的视图已经被加入视图树
  • Discussion
  • 文字参考:stackoverflow.com

    In general, this is what I do:

    1) ViewDidLoad - 需要的视图元素都在此方法加载,例如视图是一个Form,有3个label,这个方法一次成型(Whenever I''m adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.)

    2) ViewWillAppear: 这里通常不做视图的修改,而用来更新Form数据,就是给给form重新填入新数据,该页面从别的页面回来时更新。UIView的创建非常费时费力,因此到 viewWillAppear时,iphone已经蓄势待发地、兴冲冲地要去显示了,就不要在这个地方再干费时费力的事情了,纯更新数据就可以了。(I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).)

    3) ViewDidAppear: 最后,视图已经显示了,那这里可以做一些远程取数据的费时费力的工作。(Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.)


    ==============================================================

    文字来源:UIViewController类参考


    - (void)viewDidLoad

    该方法在控制器的视图载入内存时调用

    Discussion

    该方法在视图控制器(XXXViewController)已经将其视图树(视图里应有的各种东西)(view hierarchy)载入内存后调用。该方法的调用不考虑是否视图树是从nib文件(或storyboard)得来,还是纯代码获得;纯代码一般使用 loadView 方法,我们一般通过重写 loadView 方法做附加初始化,附加是指基于已有的 nib 文件或 storyboard。


    - (void)viewWillAppear:(BOOL)animated

    该方法通知视图控制器,它的视图将要(is about to) 被加入到视图树。

    Discussion

    该方法两个事件之前调用,一个是在视图将要被加入到视图树,二个是任何所需要的动画配置之前。我们可以重写该方法,实现定制如何显示视图,比如,使用该方法改变状态条(status bar)的方向和样式,以适应该视图启动时的方向和样式。重写该方法必须调用 [super viewWillAppear:animated]。.

    For more information about the how views are added to view hierarchies by a view controller, and the sequence of messages that occur, see “Responding to Display-Related Notifications”.

    Note: If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed.


    - (void)viewDidAppear:(BOOL)  animated

    该方法通知视图控制器,它的视图已经被加入视图树

    Discussion

    我们可以重写该方法执行附加任务,实现如何显示出视图。重写必须调用 super 方法。

    Note: If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed.

    -viewWillAppear:和 -viewDidAppear:区别

    -viewWillAppear:和 -viewDidAppear:区别

     -viewWillAppear:和 -viewDidAppear:区别在于will和did的区别!

    viewWillAppear是在视图出现之前调用,更新用于显示视图的信息,此时视图还没有appear。

    viewDidAppear是在视图出现之后调用,用于更新视图显示出来后,一些动画之类的操作。

    1) ViewDidLoad - Whenever I''m adding controls to a view that should appear together with the view,right away,I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example,if my view is a form with 3 labels,I would add the labels here; the view will never exist without those forms.

    2) ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So,for the example above,I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive,and you should avoid as much as possible doing that on the ViewWillAppear method,becuase when this gets called,it means that the iPhone is already ready to show the UIView to the user,and anything heavy you do here will impact performance in a very visible manner (like animations being delayed,etc).If you override this method,you must call super at some point in your implementation.

    3) ViewDidAppear: Finally,I use the ViewDidAppear to start off new threads to things that would take a long time to execute,like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user,you can show a nice "Waiting" message to the user while you get the data.

    asp.net – RadGrid在Visual Studio 2013中打开应用程序时,在不同的100%相同应用程序中进行渲染

    asp.net – RadGrid在Visual Studio 2013中打开应用程序时,在不同的100%相同应用程序中进行渲染

    我有一个.NET 4.0应用程序,它在网页中使用RadGrid.当我在第一台机器上打开我的页面时,我得到以下 HTML,
    <div id="ctl00_mainContentPlaceHolder_ctl00_mainContentPlaceHolder_radMainPanel">
       <div id="ctl00_mainContentPlaceHolder_radMain">
    
    
                           <img width="64px"src="/Data/Images/2013_09_16_17_18_37_1837_30f9.jpg" />
                       </td><td>

    当我打开第二台机器上的同一页面时,

    <div id="ctl00_mainContentPlaceHolder_ctl00_mainContentPlaceHolder_radMainPanel">
        <div id="ctl00_mainContentPlaceHolder_radMain">
    
        <tableid="ctl00_mainContentPlaceHolder_radMain_ctl00">
        <colgroup>
            <col/>
            <col  />
            <col  />
            <col  />
            <col  />
            <col  />
            <col  />
    ...............................................................

    第二个是正确的,但为什么我的第一台机器不显示任何表单元素是根本原因.

    更新:经过大量的搜索,我找到了answer at here.

    <add key="vs:EnablebrowserLink" value="false" />

    解决方法

    更新:经过大量的搜索,我找到了 answer at here.
    <add key="vs:EnablebrowserLink" value="false" />

    iOS viewWillDisappear viewWillAppear viewDidAppear等

    iOS viewWillDisappear viewWillAppear viewDidAppear等

    #pragma mark 视图即将加入窗口时
    
    -(void)viewWillAppear:(BOOL)animated{
    
       NSLog(@"视图即将加入窗口时");
       [self getdata];//加载
    }
    
     
    
    #pragma mark 视图已经加入到窗口时
    
    -(void)viewDidAppear:(BOOL)animated{
    
        NSLog(@"视图已经加入到窗口时");

         [self.collectionView reloadData];// 刷新tableView即可

    }
    
     
    
    #pragma mark 视图被驳回时调用,覆盖或以其他方式隐藏。
    
    - (void)viewWillDisappear:(BOOL)animated{
    
         NSLog(@"视图被驳回时调用,覆盖或以其他方式隐藏。");
    
    }
    
     
    
    #pragma mark 视图被驳回后调用,覆盖或以其他方式隐藏。
    
    - (void)viewDidDisappear:(BOOL)animated{
    
         NSLog(@"视图被驳回后调用,覆盖或以其他方式隐藏。");
    
    }
    
     

     

    viewDidLoad, viewWillDisappear, viewWillAppear等区别及各自的加载顺序

      ios 开发中视图的声明周期

    viewWillAppear: 视图即将可见时调用。默认情况下不执行任何操作

    viewDidAppear: 视图已完全过渡到屏幕上时调用

    viewWillDisappear: 在该视图被取消、覆盖或以其他方式隐藏后调用,
    viewDidLoad:在视图加载后被调用,如果是在代码中创建的视图加载器,他将会在loadView方法后被调用,如果是从nib视图页面输出,他将会在视图设置好后后被调用。

    viewWillAppear:当收到视图在视窗将可见时的通知会呼叫的方法

    viewDidAppear:当收到视图在视窗已可见时的通知会呼叫的方法

    viewWillDisappear:当收到视图将去除、被覆盖或隐藏于视窗时的通知会呼叫的方法

    viewDidDisappear:当收到视图已去除、被覆盖或隐藏于视窗时的通知会呼叫的方法

    didReceiveMemoryWarning:收到系统传来的内存警告通知后会执行的方法

    shouldAutorotateToInterfaceOrientation:是否支持不同方向的旋转视图

    willAnimateRotationToInterfaceOrientation:在进行旋转视图前的会执行的方法(用于调整旋转视图之用)


    代码的执行顺序

    1、alloc创建对象,分配空间

    2、init (initWithNibName) 初始化对象,初始化数据

    3、loadView从nib载入视图,通常这一步不需要去干涉。除非你没有使用xib文件创建视图

    4、viewDidLoad载入完成,可以进行自定义数据以及动态创建其他控件

    5、viewWillAppear视图将出现在屏幕之前,马上这个视图就会被展现在屏幕上了

    6、viewDidAppear视图已在屏幕上渲染完成 当一个视图被移除屏幕并且销毁的时候的执行顺序,这个顺序差不多和上面的相反

    1、viewWillDisappear视图将被从屏幕上移除之前执行

    2、viewDidDisappear视图已经被从屏幕上移除,用户看不到这个视图了

    3、dealloc视图被销毁,此处需要对你在init和viewDidLoad中创建的对象进行释放

    今天的关于从后台打开应用程序时不调用 ViewDidAppear的分享已经结束,谢谢您的关注,如果想了解更多关于- viewDidLoad 和 - viewWillApear 和 -viewDidAppear、-viewWillAppear:和 -viewDidAppear:区别、asp.net – RadGrid在Visual Studio 2013中打开应用程序时,在不同的100%相同应用程序中进行渲染、iOS viewWillDisappear viewWillAppear viewDidAppear等的相关知识,请在本站进行查询。

    本文标签: