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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-11-2010, 11:34 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 16
eddyxd is on a distinguished road
Default Can we make a function as a variable?

What I expect to do is :

We have ViewController1,2,3. and both ViewController1 & 2 have a button to add a subview to ViewController3,and there also is a button in ViewController3.

Moreover ViewController1 has a function called :-(void)helloWorld{NSLog(....)}
and ViewController2 has a function called : -(void)goodByeWorld{NSLog(.....)}.



I want the effect that if we press the button in ViewController3 and ViewController3 will have different reaction to it based who is the superview(1 or 2) of viewController3.

That is if ViewController3 is added by viewController1, ViewController3 would call "helloWorld" function. On the other hand, If ViewController3 is added by ViewController2, it would call "goodByeWorld".





I could achieve this by a complex and stupid way, that is I make many dirty work such predifined function name and many global information.

But I want to know if there is a solution that I could transmit "helloWorld" or "goodByeWorld" function as a variable to ViewController3, so ViewController3 could have a "pointer(I don't know what type may use..)" to point this function.
As a result, After any presses the button of ViewController3, it could just simply call the function pointed by the pointer and achieve this goal.

I has this idea because we can set the button selector to a function, but I don't have any idea why to implement this method in practice.


Could anyone gives me some idea or suggestion?

I will appreciate you~
THX!

Last edited by eddyxd; 09-11-2010 at 11:36 PM.
eddyxd is offline   Reply With Quote
Old 09-12-2010, 10:24 AM   #2 (permalink)
N3RD
 
Join Date: Oct 2009
Posts: 201
tychop is on a distinguished road
Default

Code:
NSString *methodName = [[NSString alloc] initWithString:@"methodToPerform"];
[self performSelector:NSSelectorFromString(methodName)];
[methodName release];
tychop is offline   Reply With Quote
Old 09-14-2010, 03:36 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 16
eddyxd is on a distinguished road
Default

Thanks.

That is exactly what I want!
eddyxd 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: 349
9 members and 340 guests
cgokey, givensur, iGamesDev, jenniead38, mraalex, PixelInteractive, raihan.zbr, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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