应用程序进入前台时如何更改ViewController中的标签 [英] How to change label in ViewController when app enters the foreground

查看:18
本文介绍了应用程序进入前台时如何更改ViewController中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用进入前台时更改视图控制器中的标签....:

i want to change a label in my view controller when the app enters the foreground....:

SalaryAppV4AppDelegate.h

SalaryAppV4AppDelegate.h

@interface SalaryAppV4AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

//----------------------------------------------    

    NSTimeInterval appEnteredBackground;

    NSTimeInterval appEnteredForeground;

    NSTimeInterval difference;

    NSString *times;

//-----------------------------------------------

SalaryAppV4AppDelegate.m

SalaryAppV4AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application

{


    //perform -(IBAction)DoThis

    FirstViewController* controller = [FirstViewController alloc];
    [controller DoThis]; 




    //releasing
    [dateFormatter release];





}

FirstViewController.m

FirstViewController.m

-(IBAction) DoThis
{

    appDelegate = [[[UIApplication sharedApplication] delegate] retain];

    //This Doesn't Work :(
    label.text = @"IT Has Worked";


    //This Works
    NSLog(@"%@", appDelegate.times);

}
//--------------------------------------------------------

我只希望 label.text ti 更改为任何内容,但视图控制器中的任何内容都没有更改...

i just want the label.text ti change to anything but nothing in the viewcontroller changes...

推荐答案

使用 App 委托中的方法和对视图控制器的实例调用

Using the method in the App delegate and a instance call to the View Controller

- (void)applicationWillEnterForeground:(UIApplication *)application {
   [ViewController.label setText:@"DA TEXT"]; //if the VC is a property.
   [[ViewController instance].label setText:@"DA TEXT"]; //if is not a property

}

如果不是属性,则必须在 VC 中设置实例类方法

If is not a property, you must set an instance class method at your VC

这篇关于应用程序进入前台时如何更改ViewController中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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