Pregunta

In my project I have only one window, in that window I have only one Custom view, nothing other than that. In that custom view I am loading one Default view, and in that default view I have one Button over there. When that button IBAction is performed, present custom view have to go and new one have to load in the same custom view of that window.

For these I tried like this, my app delegate is my window controller, in that I declared one global variable and written KVO for that observing when ever it's value get changed. In that observation method I am trying to load different xib's(custom view) according to my requirement based on value in that global variable.

Along with these I am having different ViewControllers to control different views. In that view controller classes I am loading new values into that global variable by using object of AppDelegate class.

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{    
    NSLog(@"entered into key value observing");
    if ([viewName isEqualToString:@"LoginView"]) {
        NSLog(@"Dont change the current view");
    } else {
        NSLog(@"Load new view in customView");
        [self loadNewView];
    }
}

-(void)loadNewView
{
    NSLog(@"entered into login in method");
    [[_viewController view] removeFromSuperview];
    _viewController=[[NSViewController alloc] initWithNibName:@"NewView" bundle:nil];

    [self.window setContentSize:_viewController.view.frame.size];
    [_customView addSubview:[_viewController view]];
    NSLog(@"at final step");
}

Control is moving from ViewController class to AppDelegate and in that its entering into that KVO method also, it is executing every line as I want it to execute. But its not affecting the output result.

As per as I know, it is executing every thing in that ViewController class itself by using object of AppDelegate. So it is not affecting of loading of view in CustomView in in that window.

Will any one please suggest me some solution for solving these........

¿Fue útil?

Solución

Problem is not in the code what is shown in the above question.

In the above code instance of NSViewController is creating again and again for the same purpose. Along with that try to create object of appDeligate in ViewController class by using Shared instance.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top