I have function call loop, but I want call it if my view appears, and not call it when the view disappears.
Loop Function :
-(void)updateArray
{
while (1)
{
NSLog(@"IN LOOP");
[NSThread sleepForTimeInterval:2.0];
if([FileSizeArray count] >0 || [FileCurrentSizeArray count] >0)
{
[FileSizeArray removeObjectsInRange:NSMakeRange(1, FileSizeArray.count-1)];
[FileCurrentSizeArray removeObjectsInRange:NSMakeRange(1, FileSizeArray.count-1)];
}
[FileNameArray removeAllObjects];
[UserNameArray removeAllObjects];
...
}
And in ViewWillAppear()
timer= [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector:@selector(updateArray:)
userInfo: nil repeats:NO];
And in DidDisAppear()
[timer invalidate];
timer = nil;
But it not working, it still call and my app has crash.
Can anyone help me? Thanks in advance