NSTimer unable to interact with another View Controller's Label?

I am using a SplitViewController with the the main controller named RootViewController, and the detail controller named DetailViewController. In my RootViewController, I have a timer inside my interface:

@interface RootViewController : UITableViewController <UISplitViewControllerDelegate> {
    UISplitViewController *splitViewController;     
    UIPopoverController *popoverController;
    UIBarButtonItem *rootPopoverButtonItem;

    NSTimer *counter;
}

When the user selects a row from the table from the RootViewController, the counter is set such as:

counter = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(countdown) userInfo:nil repeats:YES];

The countdown method is therefore called:

-(void)countdown { 
    DetailViewController *newDetailViewController = [[DetailViewController alloc]init];
    newDetailViewController.countdown_timer.text = @"Text Switched";
}

The code inside the method works fine almost everywhere else, and the label never seems to change no matter what code is placed in the countdown method. What is causing this not to connect with my DetailViewController's label?

Thanks!

Answers


The problem is that you are creating a new instance of DetailViewController every time the timer is triggered. This is a memory leak for one. And second, it is not altering the visible instance of DetailViewController. To alter the visible instance you must store it in a property or an instance variable.

While I am not entirely sure this will work, you can try defining your countdown method like this,

-(void)countdown { 
    DetailViewController *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
    detailViewController.countdown_timer.text = @"Text Switched";
}

This is untested and should work in theory. If this works, you don't need to have an additional instance variable.


Need Your Help

Orchard CMS build script - excluded module projects included in build

orchardcms orchardcms-1.6

I'm using Orchard 1.6 and have a question regarding the build batch file.

No able to download images from my APP

blackberry

I'm doing an app for saudi client.My problem is i'm not able to download images at client location.The same code is working out perfectly in my location(India).The only positive thing is XMLs are

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.