0

I'm trying to switch between two views right now. The problem is how it is called.

Heres the easiest way to explain my situation:

I have a Parent View. With a subclass ChildView, that contains a table. Upon selecting an object in that table, I wish to switch to a different child view of that parent view.

Parent--------- |Child 1 |Child 2

Child 1 is a subclass of Parent to allow me to access a method in Parent that switches between Child Views 1 and 2, but for some reason it wont work when accessing it from Child 1.

Any clues on how to do this? Heres the basic code:

Child 1 - (void) changeViews

[super methodToSwitchChildViews];

Parent - (void) methodToSwitchViews

[self.child1.view removeFromSuperView];
[self.view insertSubView:child2.view atindex:0];
1
  • What do you mean that your child is a subclass of your parent? That would only mean that the child have properties of it's parent, not that it has a connection whit his parent.
    – Cyprian
    Commented Jul 29, 2011 at 6:07

2 Answers 2

0

Super is the class that precedes a (sub)class in inheritance. Here the children seem to be views on a superview (parent). So use superview, and not super.

0

Okay, I dug around quite a bit and finally figured out a solution. In case anybody ever has the same problem here's what you do:

In the .h file of the child view do

@class parentViewName

Then in the .m file add

#import "parentViewName.h"

...

- (void) functionToRemoveSelfFromView {
   parentViewName *PARENT = [[parentViewName alloc] init];

   // You must have a method in the parent view to toggle or remove the subview, the way
   // you want it done, then call it with the new delegate. Make sure it doesn't set this 
   // view to nil or releases it because this method has yet to return. If animating do not
   // hide this view either.

   [PARENT methodToRemoveSelfFromView];
   [PARENT release];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.