iOS 7 - viewDidLoad和viewDidAppear之间的区别 [英] iOS 7 - Difference between viewDidLoad and viewDidAppear

查看:719
本文介绍了iOS 7 - viewDidLoad和viewDidAppear之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,这可能不是一个编程问题,而是更多关于iOS生命周期功能性质的询问。

Sorry but this may not be a programming question per se but more of an inquiry over the nature of iOS lifecycle functions.

我有一个应用程序,我有一个函数创建四个数组并通过数据库查询填充它们。首先,我从 viewDidLoad 函数调用该函数,但是,每当加载View时,在视图实际出现之前需要花费时间(大约3-4秒)。所以我做的是创建了一个 activityViewIndicator ,我的 viewDidLoad 函数看起来像:

I have an application where I have a function that creates four arrays and populates them via database queries. At first, I called the function from the viewDidLoad function, however, whenever the View is loaded, it takes time (around 3-4 seconds) before the view actually appears. So what I did was I created an activityViewIndicator and my viewDidLoad function looks something like:

- (void)viewDidLoad:(BOOL)animated{
    [super viewDidLoad];

    NSLog(@"viewDidLoad Entered");
    [self.activityIndicatorView startAnimating];

    partInput.delegate = self;
    brandInput.delegate = self;
    barcodeInput.delegate = self;
    itemNameInput.delegate = self;

    //initializeArrays is the function that initializes the arrays
    [self initializeArrays];

    [self.activityIndicatorView stopAnimating];

}

但是这不起作用,因为 viewDidLoad 当应用程序仍在上一个视图中时,将触发该功能。视图仅在 viewDidLoad 已完成后才会显示。所以我做的是将数组初始化移动到我的 viewDidAppear 函数,它看起来像:

However this doesn't work since the viewDidLoad function is triggered when the application is still in the previous View. The View only comes into display after viewDidLoad is already done. So what I did instead was move the array initialization to my viewDidAppear function which looks like:

- (void)viewDidAppear:(BOOL)animated{
    NSLog(@"viewDidAppear loaded successfully");
    [self.activityIndicatorView startAnimating];

    partInput.delegate = self;
    brandInput.delegate = self;
    barcodeInput.delegate = self;
    itemNameInput.delegate = self;

    [self initializeArrays];

    [self.activityIndicatorView stopAnimating];

}

然而,当我部署它时,没有任何延迟,使activityIndi​​catorView无用。

However, when I deployed this, there was no delay whatsoever, making the activityIndicatorView useless.

我的问题是,为什么我认为 viewDidLoad 和<$之间存在性能差异 C $ C> viewDidAppear ?

My question is, why does it seem to me that there's a "performance difference" between viewDidLoad and viewDidAppear?

推荐答案

请每次按照以下查看控制器生命周期。您将以这种方式对应用程序的编码和性能感到惊讶。

Please Follow the below View Controller Life Cycle Every Time. You will be amazed with the coding and performance of your application in this manner.

这篇关于iOS 7 - viewDidLoad和viewDidAppear之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆