I have a UISegmentedController i have 3 UIViewControllers Like photos,frames,gallery. I add those 3 Views in Superview Using 'addSubView'. In frames view i have added a subview that name as EditView. In EditView i have done some changes, i want to update these changes in frames view. But when am removing EditView from frames view any single method doesn't calling. Then how to update the changes from subview in superview. Tree: UISegmentedController -> Frames(Su) -> EditViews(Subview). Can any one help me..
3 Answers
I found the code to update something in superview from subview. Please use this code in your subview. It will call your superview viewWillAppear method. You can use another method instead of viewWillAppear. It works for me.
for (UIView* next = [self.view superview]; next; next = next.superview)
{
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
{
[(UIViewController*)nextResponder viewWillAppear:YES];
}
}
-Yuva.M
You could access the super view of any UIView
by using the superview
property of UIView
.
The below statement will be in your EditView
.
FrameView* mySuperFrameView = (FrameView*)self.superview;
and the next statement could be calling the super view function.
[mySuperFrameView updateMySuperView];
updateMySuperView is the part of your superview
.

- 31,697
- 9
- 72
- 76
-
@Jhaliya thanks for your spot respose. i'll implement your code on my application. – Yuvaraj.M Jun 10 '11 at 05:59
-
Hello friend i implemented your code. i Called FrameView *mySuperFrameView = (FrameView*)self.superview; in EditView but one bug is in this line that was 'Request for member 'superview' is something not a structure or union'. self.superview option on available. Any more ideas. pls save my day.. – Yuvaraj.M Jun 10 '11 at 06:04
-
just change FrameView* mySuperFrameView = (FrameView*)self.view.superview; – iAmitWagh Jun 10 '11 at 06:12
-
i found one answer for my question, it works for me. Thanks for you friends. – Yuvaraj.M Jun 10 '11 at 07:19
-
@Yuvaraj.M : Good, Suggest you to share that with others . – Jhaliya - Praveen Sharma Jun 10 '11 at 10:34
-
@Jhaliya now i cant upload code. I tried when i found this code, but stackoverflow not allow me to post a code. I'll post that answer after 4 hrs. This is that code, for (UIView* next = [self.view superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { //[(UIViewController*)nextResponder viewWillAppear:YES]; [(UIViewController *)nextResponder viewDidAppear:YES]; } } Implement this code in your subview. It will call the method of its superview. – Yuvaraj.M Jun 10 '11 at 12:47
Removing a view from its superview releases it.
Submit your changes before removing the editView from its superview. You could overwrite removeFromSuperview
in your editView, and do your data manipulation before calling super removeFromSuperview
.
Or your view controller could take data from the editView before removing it.

- 9,842
- 3
- 37
- 57