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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2008, 10:17 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 204
Default Call function from other view (stupid question)

How do I access the "parent" view from a pushed view? I want to call a function from the view that pushed the current view into place.

I thought I might have been close with the following code, but apparently it isn't anything close.

Code:
[[[self navigationController] PARENTVIEW] myFunction];
peejavery is offline   Reply With Quote
Old 10-28-2008, 03:06 AM   #2 (permalink)
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 401
Default

When you create the view you need to pass through who the parent is.

The easiest way to see this in action is in the BubbleLevel source code.

Look at the following line in the LevelViewController:

Code:
levelView = [[LevelView alloc] initWithFrame:applicationFrame viewController:self];
Here you can see that it passes the viewController "self". So now the view knows who is the parent.

Check the LevelView.h and .m files for more information on how to correctly set this up.

IMPORTANT: Do NOT add [viewController release]; to the dealloc of the view or you will crash your app.

I use "self.viewController = nil;" instead.
__________________
BUZZER! : iTunes Library Music Quiz (1 or 2 Player)
Stitch is offline   Reply With Quote
Old 10-28-2008, 08:20 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 204
Default

But, that example doesn't have anything to do with pushing view controllers. I need the pushed window to access the window that pushed it.
peejavery is offline   Reply With Quote
Old 10-28-2008, 10:16 AM   #4 (permalink)
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 401
Default

Have you even tried?

It will work exactly the same. Just pass the view controller (self) at the time of creating it so it knows who started it.

I'm sorry but I am not sure of your programming level.
__________________
BUZZER! : iTunes Library Music Quiz (1 or 2 Player)
Stitch is offline   Reply With Quote
Old 10-28-2008, 11:05 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 204
Default

I have tried all sorts of working with that code. However, it just keeps throwing me errors. I will have to come up with some other sort of work-around. Maybe something to do with modal views.


Quote:
Originally Posted by Stitch
I'm sorry but I am not sure of your programming level.
Objective-C is rather new to me. I have been programming for Windows systems for about 9 years. I'm on the moderating staff over at CodeGuru.
peejavery is offline   Reply With Quote
Old 10-28-2008, 11:12 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 204
Default

Thanks for all you help Stitch!

I ended up passing it into a custom method on the pushed view controller.

Code:
- (void)setParent: (UIViewController *)viewController {
    parentView = viewController;
}
peejavery 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
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
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 02:34 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0