-1

How to make Thread paused or stopped when view dispear i do that:

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:(BOOL)animated];    

     [NSThread sleepForTimeInterval:10];
}

but didnt work

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Med Reda
  • 36
  • 1
  • 5
  • Why do you want this?? It's not good practice to pause a thread. – Inder Kumar Rathore Dec 14 '12 at 16:22
  • As already stated several times, you really really really shouldn't be doing this. What exactly are you trying to achieve? We may be able to offer a better solution. – Mick MacCallum Dec 14 '12 at 16:46
  • I have two viewcontroller, in the first view i display images from database and if the user click button bar to pass in the second view i want to stop the thread in the first view and when the user comeback in the first the thread continuous – Med Reda Dec 15 '12 at 10:09
  • don't sleep thread, its not food habit .. just disable your button... – Rajneesh071 Dec 19 '12 at 06:40

3 Answers3

1

You should do this in viewWillDisappear but more likely you probably shouldn't do this.

mkral
  • 4,065
  • 4
  • 28
  • 53
1

You should never sleep for longer than a few milliseconds in the UI thread. If you do the OS will kill your application, in addition to it behaving poorly.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
0

Do you button disable instead of NSThread sleep

[yourBtn setEnabled:NO];  

When you retrieve complete data then enable it

[yourBtn setEnabled:YES]
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74