English 中文(简体)
传承母公司
原标题:Calling a parent UIViewControllers function

奥凯,我有问题,无法找到我做错的事情。

I have a UIVievController with a view and some functions and stuff. One is to open (from a button in a actionsheet) another UIVeiwController. Looks like this:

PersonalSettings *personalSettings;
-(IBAction) displaySettingsMenu:(id)sender
{
    personalSettings = [[PersonalSettings alloc] 
                        initWithNibName:@"PersonalSettings" 
                        bundle:nil];
    [self.view addSubview:personalSettings.view];
    [SettingsSheet dismissWithClickedButtonIndex:0 animated:YES];
}

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 ViewController (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 ViewController I remove the view with:

[self.view removeFromSuperview];

What I have to do from here is to call the update function from the child view for the parent view.

我发现这方面的一些法典,但“超级阶级”而不是“超级概貌”除外,因为超级概览没有出现在清单中。 类似:

[self.view removeFromSuperview];

MainViewController *Parent = (MainViewController *)self.superclass;
[Parent updateView];

是否有“魔mag”我可以说什么,如“母体观点”?

I hope I ve made the problem understandable. :)

EDIT:

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.

从儿童身上写成:

MainViewController* Parent = [[MainViewController alloc] init];
Parent.delegate = self;
Parent.TheLabel.text = @"foo";

......这并不奏效,即使它确实找到了标签和一切东西。 如果儿童试图这样做:

NSLog(@"Parent label: %@", Parent.TheLabel.text);

它标有“字面标签:(null)”。

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?

问题回答

If you are familiar with the delegate model, then make your parent view the delegate and pass information back that way from the child. You ll find some good docs about it on the Apple website.

基本上,你在孩子的造物方面增加了一个代表处:

child = [[ViewController alloc] initWithDelegate:this withNibName:@"myNib"];

然后,在儿童阶层,当你收到信息时,你可以进入贵国代表的田地/方法。

- (void) volumeDidChange:(int)volume
{
    delegate.volume = volume
}

或如此。 good!

Since i m just a newbe and added the child view as "addSubview" i had theese problems. Changing the view with - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated did the trick! Thanks any way an specially thanks to kubi :)

i agree with aeoliant, using delegate model might be more approapriate. a simple exlanation here Working with delegate in objective-c

如果您寻求一种通向特定控制器的父母的通俗方式,则研究这种方法:

+ (YOURTABBARCONTROLLER*)parentTabBarController:(UIResponder*)view {
    id nextResponder = nil;
    id v = view;
    while (nextResponder = [v nextResponder]) {
         if ([nextResponder isKindOfClass:[YOURTABBARCONTROLLER class]])
            return nextResponder;
         v = nextResponder;
    }
    return nil;
 }

它将使回复链条脱节,使你回到其中发现的第一类特定类别。 页: 1 缩略语 因此,你会说:

 YOURTABBARCONTROLLER* parent = [self parentTabController:self.view];

(如果是你的子女控制人,你在其中界定了上述方法)。

这是你可以接触的最近一点,AFAIK。 也可将这种方法归入国际会计师联合会一类,因此,你总是会这样做。

EDIT:

如果你使用<代码>+,那么就采用这样的方法:[CLASSNAMEnerTabController:view],即CLASSNAME是你定义的类别。 无论如何,您可在方法申报中使用<代码>-,如上所述,它将使用<代码>自行。

如不为您工作,请按您的定义说明全部方法,以及你所说的确切方式。 也不妨增加这一行文:

           NSLog(@"Found Responder: %@", nextResponder); //-- ADDED THIS

作为<代码>第1行的“路程”,以便该方法能够记录其在回复链中发现的情况。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签