2011-11-14 63 views
0

在我的應用程序來當我運行定時器時按下按鈕,取得按鈕標籤名「空」,從背景的委託​​方法

我想運行在背景和定時器時讓我用這個方法,

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
    FirstViewController *view = [[FirstViewController alloc]init]; 
    [view Startbtnpress]; //call the startbtnmethod 
} 

在Startbtnpress方法,

 -(IBAction)Startbtnpress 
{ 

    NSLog(@"start.titleLabe:%@",start.titleLabel.text); 

    if([start.titleLabel.text isEqualToString:@"START"]) 
{ 
    myticker = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(ShowActicity) userInfo:nil repeats:YES]; 
} 
    else if([start.titleLabel.text isEqualToString:@"STOP"] 
{ 
    [myticker invalidate]; 

} 
} 

當首次調用的NSLog啓動按鈕方法(@ 「start.titleLabe:%@」,start.titleLabel.text); 我得到的 「START」

當我通過

 - (void)applicationWillEnterForeground:(UIApplication *)application 

進來的NSLog(@ 「start.titleLabe:%@」,start.titleLabel.text); 我得到空值?

出了什麼問題?

+0

釋放的對象。 –

回答

1

嘗試調用viewDidLoad中 [view Startbtnpress]; 而不是作爲視圖可能不會在當時laoded(特別是如果從的.xib文件加載)

+0

這就是問題。它返回null,因爲它尚未創建。 – Davido

+0

我嘗試調用[視圖Startbtnpress] viewDidLoad中內及內方法 - (無效)applicationWillEnterForeground:(UIApplication的*)應用 { FirstViewController *視圖= [[FirstViewController的alloc] INIT]; [view viewDidLoad]; }但是,仍然變得空... –