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 06-24-2010, 08:13 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 2
mp43819 is on a distinguished road
Default Calling function in the first view from the other viewcontroller

Hello everyone, I hope that you will succeed in at least a little to clarify me how and what to do, I'm sure I'm wrong, so I really need an expert opinion. I have two viewcontroller together with nibs what I want is to call function that is in first class from another ViewController, the problem is that another viewcontroller manages to call this function but the only thing I can see that is done is NSlog which outputs in the console (which I put in that position to know that the function is called)

example:
FirstViewController.m

Code:
    -(void)drawingFunction:(NSString*)inputText{
NSLog("Feature was launched");
/* showing stuff in FirstView.xib */
}
SecondViewController.m

Code:
-(void)turnOnFunction:(id)sender{
FirstViewController *stuff= [[PrviViewController alloc] init];
[stuff drawingFunction:@"ShowAll"];
}
Basically when I call that function in the PrviViewController.m meaning without reference to the outside e.g.

Code:
[self drawingFunction:@"ShowAll"];
everything is well displayed, but when I try to call this function from SecondViewController.m all I see is just a "feature was launched" on the console

I really don't know what to do ...
mp43819 is offline   Reply With Quote
Old 06-24-2010, 10:52 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

I am assuming that the first view controller is created first and probably creates the second view controller. So in the second view controller create an iVar/property to hold a reference to the first view controller. I do that all the time.

If the first and second view controllers are unrelated. Meaning one not being a subview or one creates the other, then I would not put the method in either of the view controller, but in some other shared NSObject class that you create, like a helper class. I do that all the time too.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 06-24-2010, 01:45 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 2
mp43819 is on a distinguished road
Default

The point is such that it was initially FirstViewController and its NIB and later expand of the applications needed for a new view with corresponding class to control things (specifically in the new class there are UISwitches that turns on and turnsoff a specific functions in FirstView)

If you have any suggestion to make it painlessly or on more elegant way I am open to all suggestions. (Thanks for the post above)
mp43819 is offline   Reply With Quote
Old 06-24-2010, 02:32 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

Quote:
Originally Posted by mp43819 View Post
The point is such that it was initially FirstViewController and its NIB and later expand of the applications needed for a new view with corresponding class to control things (specifically in the new class there are UISwitches that turns on and turnsoff a specific functions in FirstView)

If you have any suggestion to make it painlessly or on more elegant way I am open to all suggestions. (Thanks for the post above)
Like above, I would just have the second view have a reference to the first view.

@interface MySecondViewController {
MyFirstViewController *firstViewController;
}

@property (nonatomic, retain) MyFirstViewController *firstViewController;

now you can call methods on firstViewController from the second view controller.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 06-25-2010, 12:31 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 16
justagruvn is on a distinguished road
Default

Mark,

thanks for the input. I am having the same issue. In a related question..

If you have a "FirstLevelViewController" .h and .m class that a navigation controller loads on startup... what is the name of the FirstLevelViewController instance?? Is it firstLevelViewController with the first letter uncapitalized?

Thank you. Very helpful information. Oh shucks.. one other question... Say you wanted to make a very basic (not core data) data class with only one instance and this stored your data and your first and second level view controllers updated.. Where would you initialize that object? In app delegate?? how would you give these same references to the view controllers?

Thanks bunches!

Michael
justagruvn is offline   Reply With Quote
Old 05-18-2011, 09:49 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default

Quote:
Originally Posted by bytor99999 View Post
Like above, I would just have the second view have a reference to the first view.

@interface MySecondViewController {
MyFirstViewController *firstViewController;
}

@property (nonatomic, retain) MyFirstViewController *firstViewController;

now you can call methods on firstViewController from the second view controller.

Mark
Hello

I coded my app with two viewcontrollers, and placed the code above that you stated but I cant seem to access the functions , if I had a function like :

Code:
- (IBAction)hideLeftScroll:(id)sender {
	leftScroll.hidden = YES;
	//debug only
	NSLog(@"Hide Left Scroll");
}
and wanted to access this function from the second vewcontroller what would I need to do!?
famictech2000 is offline   Reply With Quote
Reply

Bookmarks

Tags
functions, uiviewcontroller

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: 324
7 members and 317 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
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:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0