Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-22-2010, 09:51 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 2
Default I don't understand the concept of selectors

I don't understand the details of why and how to use selectors in objective -c. I understand that at runtime messages are 'converted' to selectors. But I don't understand why I should use them in practice. For example what is the purpose of calling the animateBall method in the initializerTimer method using a selector?


-
Code:
(void)animateBall:(NSTimer *)theTimer {

	ball.center = CGPointMake(ball.center.x +ballMovement.x,
		ball.center.y + ballMovement.y);
}

-
Code:
(void)initializeTimer
{
	float theInterval = 1.0/30.0;
	[NSTimer scheduledTimerWithTimeInterval:theInterval target:self selector:@selector(animateBall:) userInfo:nil repeats: YES];

}
Russell is offline   Reply With Quote
Old 09-02-2010, 08:14 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

A selector is essentially a pointer to a method (except that it points to the name rather than to the implementation). It is used anywhere you need to specify which method should be called in a certain circumstance. If you are calling the method right now, then you can refer to it directly and there is no need for a selector. But if you are setting up something to be called at a later time, then you would have to specify that method with a selector.

Last edited by RLScott; 09-02-2010 at 08:21 AM.
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 272
20 members and 252 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:01 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0