Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

NSTimer, UITableView and access NSMutableArrays

tomdekuijpertomdekuijper Posts: 4New Users
edited January 2010 in iPhone SDK Development
Hello,

I am trying to make a stopwatch function which would seem to me very simple. However I am struggeling on a number of topics.
I have set up a timer (scheduledTimerWithTimeInterval) and the stopwatch is running fine. However I cannot access the NSMutableArray
i have created in the selector method for the timer. I am using a NSMutableArray to record the different NSDates every time the users
presses the ' LAP' button. In the TableView i am update the rows with these laptimers but get bad access error on the following code:
-(UITableViewCell*)tableView:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString * const kLapCellID = @"LapsCellID";
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:kLapCellID];
if (cell ==nil) {
cell = [[[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:kLapCellID] autorelease];
}
//calculate lap
NSInteger index = indexPath.row;
NSDate *endOfLap = [self.Laps objectAtIndex:index+1];
NSDate *startOfLap = [self.Laps objectAtIndex:index];
NSTimeInterval lapTime = [endOfLap timeIntervalSinceDate:startOfLap];
    int minutes = fmod((lapTime / 60), 60);
int seconds = fmod(lapTime, 60);
int hunderths = (fmod(lapTime, 60)-seconds) * 100;
cell.textLabel.text = [NSString stringWithFormat:@"Lap %d  %02d:%02d:%02d",
(indexPath.row+1), minutes, seconds, hunderths];
return cell;
}

How can I overcome this? And how can I ensure NSMutableArrays can be used throughout the code???

many thx in advance,

tom
Post edited by tomdekuijper on

Replies

Sign In or Register to comment.