Skip navigation.
 
mlNSTimer
FROM : Bill Allaire
DATE : Tue Apr 03 21:35:43 2007

I'm new to Cocoa, so please bear with me.

I initialize a timer when overriding init:
       timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self 
selector:@selector(setDevState:) userInfo:nil repeats:YES];

I create an array to manipulate during each timer event in awakeFromNib:
       tableArray = [NSArray arrayWithObjects:aisle1Table, aisle2Table, 
aisle3Table, nil];
Each object is a NSTableView.

-(void)setDevState:(NSTimer *)aTimer
{
   Some calls to Mysql
   ...
   if ([dsdsst compare:@"ONLINE"] == NSOrderedSame)
       [[tableArray objectAtIndex: aisle] setBackgroundColor:green]; // 
Green is NSColor *
   else
       [[tableArray objectAtIndex: aisle] setBackgroundColor:red]; // Same 
with red
   ...
}

In awakeFromNib: I call:
       [self setDevState:timer];

When the program runs, the three tables are colored according to 
their status (online or offline) as expected.  In the debugger the 
tableArray has a count of three objects.  When the timer fires and 
enters setDevState: the count of tableArray shows and when this 
object is accessed, GDB is brought up:
   {(int)[$VAR count]} objects

If I comment out the line [self setDevState:timer]; and wait for the 
timer to fire, the debugger is brought up with the same behavior: no 
count in the array.  I don't understand why I can call setDevState: 
outside a timer and it works fine but when called by way of the timer 
things go awry.

Related mailsAuthorDate
mlNSTimer Bill Allaire Apr 3, 21:35
mlRe: NSTimer James Bucanek Apr 3, 21:57
mlRe: NSTimer Sherm Pendley Apr 3, 22:03