Top of the page
Close

This is a red error

This is a red error

This is a red error

Example of threading in iPhone SDK (Objective-C using NSThread)

Ondrej Rafaj on 2009.09.04 17:38:18

Example how to use create a new thread using NSThread to run some method in the background of your application.
- (IBAction) startThreadButtonPressed:(UIButton *)sender {
	
	[NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
	
}

- (void)startTheBackgroundJob {
	
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
	[NSThread sleepForTimeInterval:3];
    [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
    [pool release];
	
}

- (void)makeMyProgressBarMoving {
    
	float actual = [threadProgressView progress];
	if (actual < 1) {
		threadProgressView.progress = actual + 0.01;
		[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
	}
	
}
Update: Full tutorial about threading with NSThread and sample application is here

Ondrej Rafaj

Ondrej Rafaj

Independent iPhone developer @ ondrej-rafaj.co.uk

I am available to give you a free quote or start working on your project ... just give me a call or drop a line. Please find all my details on my portfolio site ondrej-rafaj.co.uk

Back to top Comment

Comments ... Why not to get involved!
  • fourfqueema

    fourfqueema

    from 94.77.**.** @   

    ????????? ??? ????? ?????? ????????? ???????????????? ????????? ??? ? ????????????? ?????? ?????????? ?? ?????? ?????? ???? ? ?????????? ?????? ? ???????? 90?? ?????, ?????? ? ?????? ? 2002 ?? 2008 ???, ???? ?????????????, ? ????? ?????????? ????????? ???????? ???????. ??????? ?????? ??? ????? ? ?????????? ?????? "????????? ??????????? ????? ??????? ??????????? ?????????".
    ?.??????? ??????, ??????? ?? ????? ???????? ????????? ? ???????? ?????????? ???????. ?? ?????????, ??????? ??????????? ???????, ???????? ??????????? ????????????????, ? ????????????? ??????, ?????????? ??? ???????????? ??????? ??????? ?????? ? ??????????, ?.?. ?????????????, ????????????????, ??????????? ???????????. "?? ??????? ???? ?????? ??????", - ??????? ??.
    ??????????? ???? ??????????????????? ??? ?????? ????????, ??????? ?? ???????? ??????? ???? ??? ??????. ??????????? ??????? ??????????? ???????? ??????????? ? ?????????? ??????????? ???????. ?.??????? ??????, ??????? ?????? ??????????? ??????? ????????? ????? ???????????????? ??????? ??????????? ??????. "? ????????? ??? ?? ?????? ???????? ????????????????? - ???????? ??? ?????????? ????????? ????????. ? ? ?????? ???????, ?????????????, ?? ???????? ??????????? ? ?????????? ??????? ? ???????????? ????????", - ??????? ??. ???????? ?????? ? ?????? ?????????? ?????????? ?? ???????? ????????? ? ????, ?.?. "??????? ??????????????? ????????".
    ??? ?????????: http://tomsk1.belousow-sergey.ru/
    ?? ?????? ???????:
    [URL=http://hotin1.100webspace.net/hentai-sex-scenes.html]hentai sex scenes[/URL]
    [URL=http://businessme.coconia.net/grant-money-to-start-a-business.html]grant money to start a business[/URL]
    [URL=http://grisha12.100webspace.net/usa-sex-guide-lansing.html]usa sex guide lansing[/URL]
    [URL=http://hotin1.100webspace.net/girls-using-sex-machines.html]girls using sex machines[/URL]
    [URL=http://fomosex1.freeserverhost.com/prejean-sex-tape.html]prejean sex tape[/URL]

Comment

Leave a Reply


Back to top

IE SUCKS, DON'T USE IT :) Digg this page