views:

35

answers:

2

In my app, a specific ViewController overlays itself (as navigational buttons) over a galleryViewController that can be switched around.

However, my issue is that after I allocate a new galleryViewController, then switch to that view, I want to be able to send back information regarding what is being displayed to the original ViewController.

So within this galleryViewController I alloc a viewController object and attempt to do what needs to be done.

However, I've come to understand that this viewController object is a NEW allocated object. So the various UIButtons I want to make hidden and unhide are NOT the ones currently present in the superview - they haven't even been allocated.

How can I access the original viewController - it's the one that is declared and addedToTheSubview in the appDelegate.

I am not really sure how much I was able to properly relate, if there are any specific code questions please ask and I can post it. I don't have any errors in my code, just more of a question of syntax.

I posted this same question on iphonedevsdk as well, so if I get any info from there I'll gladly update the progress of this question.

A: 

If I understand what you're asking, I would suggest that you declare the views as IBOutlets in the ViewController. Then, using IB, attached the views that you want to manipulate to those IBOutlets and use those objects throughout your code.

Hope that helps...

BB

Bobby B
Personally, I stay away from IB.And I changed the declarations of my various UIViewControllers in my parentViewController .h file to include IBOutlet - however I still don't understand how to access this parentViewController and its methods from a childViewController.
Smokin Joe
I probably won't be able to help you much if you steer clear of IB. I have to admit I'm back to being a bit fuzy as to what you're after. Because you keep referencing these two views as a parent and child, I'm going to assume the child is a sub-view of the parent. If that's the case - you can get a reference back to the parent by using [self superview].Does that help out?
Bobby B
Yes, i'm still relatively new (3-4 months) at this and definitely need to work on using the correct terminology.I'll give that a shot. And I'm fairly certain that yes, that is what I'm doing. I'm using insertSubview: for another viewController - and that viewController needs to be able to target the parent that inserted that subview. ..Man I hope this makes sense..
Smokin Joe
A: 

So I've learned I need to access it through the appDelegate so I have this line of code in my childViewController:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
ParentViewController *pvc = appDelegate.viewController;
[pvc placeOverlays:index];
[pvc release];

However, some odd behavior takes place. If I remove the [pvc release], I can go through all my gallery slides, my UIButtons are manipulated exactly as I would want... but I just feel that [pvc release] is supposed to be there.

But with it I can only go through the above code twice before it crashes with an EXC_BAD_ACCESS. I think it probably has something to do with my rudimentary knowledge of the iOS syntax, but anyone willing to explain to me would be greatly thanked!

So to anyone following along, remove [pvc release]; from my code above and it all works superfantastic.. Even though, I feel that may lead to a memory issue.

Smokin Joe
Where are you calling that code at? If that's in your init you might want to move pvc to be a class variable and then release it in your dealloc.
Bobby B
I have it being called in the childViewController.essentially the childViewController needs to call the[pvc placeOverlays:index];method in order for the view that originally alloc'd and added the childViewController to make the appropriate Visual Changes.I'm thinking that maybe my parentViewController might contain a little too much and should perhaps separate it into 2 or even 3 viewControllers.
Smokin Joe