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 03-29-2009, 05:05 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Question Trying to call a function within a class

This seems like it should be simple to me, but I'm having a hard time finding a way to do it. I have a class that builds a view that has a button within it. I need that button to make something happen in the view that I've got an object of the class in. I've setup the button to call an action from within the class.

[myButton addTarget:self action:@selector(testAction:) forControlEvents:UIControlEventTouchUpInside];

This calls the following function within the class.

- (void)testAction:(id)sender{
}

Within this I need to be able to call a function in the view that I have the class in. I have a function ready in the view that hides the class and does some other stuff when it runs. I need a way to run this function from the testAction or a better way to make it happen.
__________________
Shablabla
kgodard is offline   Reply With Quote
Old 03-29-2009, 05:52 PM   #2 (permalink)
ftm
FasterThanMonkeys.com
 
Join Date: Mar 2009
Location: Southern California
Posts: 523
ftm is on a distinguished road
Send a message via AIM to ftm
Default

If testAction is defined in your ViewController for the view in question, you should be able to do:

Code:
[self.view methodNameInView];
from your testAction method where "methodNameInView" is the name of the method you want to call in your view.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 03-29-2009, 05:55 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Default

testAction is defined in the class.
__________________
Shablabla
kgodard is offline   Reply With Quote
Old 03-29-2009, 07:21 PM   #4 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 11
The_Messen9er is on a distinguished road
Default

Quote:
Originally Posted by kgodard View Post
This seems like it should be simple to me, but I'm having a hard time finding a way to do it. I have a class that builds a view that has a button within it. I need that button to make something happen in the view that I've got an object of the class in. I've setup the button to call an action from within the class.

[myButton addTarget:self action:@selector(testAction forControlEvents:UIControlEventTouchUpInside];

This calls the following function within the class.

- (void)testActionid)sender{
}

Within this I need to be able to call a function in the view that I have the class in. I have a function ready in the view that hides the class and does some other stuff when it runs. I need a way to run this function from the testAction or a better way to make it happen.


From what I understand, the structure of your program is the following:

RootView ->contains-> YourClass ->contains -> anotherView

and you need to call a method in RootView from YourClass.

If this is the case then you need some way do address RootView from within YourClass. You could simply create a class variable i.e. a pointer to a View of type RootView. Then when you create YourClass inside the RootView, you could set that pointer to the RootView.

example:
in RootView

YourClass *c = [[YourClass alloc] init];
[c setRootView:self];


Then in your testAction method, you could call:
[self.rootView doYourThing];

Hope it helps
The_Messen9er is offline   Reply With Quote
Old 03-29-2009, 08:01 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Default

Of course! That is exactly what I needed. Thank you so much it worked great!
__________________
Shablabla
kgodard is offline   Reply With Quote
Reply

Bookmarks

Tags
action, class, function, selector, uibutton

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: 341
5 members and 336 guests
blueorb, guusleijsten, Kryckter, LEARN2MAKE, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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