Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a parent UIViewControllers function
    primarykey
    data
    text
    <p>Okay, I have a problem and has not been able to find what I'm doing wrong.</p> <p>I have a <code>UIVievController</code> with a view and some functions and stuff. One is to open (from a button in a actionsheet) another <code>UIVeiwController</code>. Looks like this:</p> <pre><code>PersonalSettings *personalSettings; -(IBAction) displaySettingsMenu:(id)sender { personalSettings = [[PersonalSettings alloc] initWithNibName:@"PersonalSettings" bundle:nil]; [self.view addSubview:personalSettings.view]; [SettingsSheet dismissWithClickedButtonIndex:0 animated:YES]; } </code></pre> <p>This works like a charm and I can make som updates in this view. When I close this view all the settings are updated properly and the view disappears, but what I want to do is to reload the parent <code>ViewController</code> (View?) so I can see the new settings I've made. I have a void function for this in the parent, but how can I call it? When the save-button is hit in the child <code>ViewController</code> I remove the view with:</p> <pre><code>[self.view removeFromSuperview]; </code></pre> <p>What I have to do from here is to call the update function from the child view for the parent view.</p> <p>I found some code for this, but with the exception "superclass" instead of "superview" since superview does not appears in the list. Looks like this:</p> <pre><code>[self.view removeFromSuperview]; MainViewController *Parent = (MainViewController *)self.superclass; [Parent updateView]; </code></pre> <p>Is there something "magic" I can do to say something like "reload parent view"?</p> <p>I hope I've made the problem understandable. :)</p> <p>EDIT:</p> <p>Really thanks you gyus, i'm closer now. I'm not 100% sure how this delegate thing works (yet) but i'm close to a solution. Actually, i realized don't even have to run a method, just update a label. </p> <p>From the child, i have written this:</p> <pre><code>MainViewController* Parent = [[MainViewController alloc] init]; Parent.delegate = self; Parent.TheLabel.text = @"foo"; </code></pre> <p>...but this does not work - even if it really finds the label and every thing. And if i from the child tries this:</p> <pre><code>NSLog(@"Parent label: %@", Parent.TheLabel.text); </code></pre> <p>it logs "Parent label: (null)".</p> <p>But, however, i can reach the update function from the child now and it runs. The problem is that this function takes values from other labels (in the parent view) and this is where it crashes - they all say null when i run the function from the child. Even if their not. Any ideas why?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload