problema conceptual o técnico con la programación de Cocoa

votos
2

Me veo en la necesidad de acceder a viewcontroller desde su vista.

Aquí está el método

-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{
    //Remove whatever view is currently loaded at index 0, this index is only to be used by page views
    UIView *oldview = [self.view.subviews objectAtIndex:0];

    [UIView beginAnimations:@View Flip context:nil];
    [UIView setAnimationDuration:s];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    [newviewcont viewWillAppear:YES];
    //[oldview viewWillDisappear:YES];
    [oldview removeFromSuperview];
    [self.view insertSubview:newviewcont.view atIndex:0];
    //[oldview viewDidDisappear:YES];
    [newviewcont viewDidAppear:YES];

}

Básicamente, estoy tratando de escribir un método genérico de cambio de vista que es llamado por el controlador raíz para intercambiar vistas de subviewcontorllers desde la vista de controladores raíz.

Paso en un controlador de subvista y puedo eliminar la subvista actual. Pero para hacer una animación de conmutación de visualización adecuada necesito acceder al controlador de vista de vistas actual. ¿Es este el enfoque equivocado y se puede hacer?

Publicado el 02/03/2009 a las 00:57
fuente por usuario
En otros idiomas...                            


3 respuestas

votos
1

Agregué un miembro al controlador raíz que se aferra al controlador de vista sub actual (currentController) y se refiere a él cuando se realiza un cambio de controlador

-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{


    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:s];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    [newviewcont viewWillAppear:YES];
    [self.currentController viewWillDisappear:YES];
    [self.currentController.view removeFromSuperview];
    [self.view insertSubview:newviewcont.view atIndex:0];
    [self.currentController viewDidDisappear:YES];
    [newviewcont viewDidAppear:YES];
    [UIView commitAnimations];


    self.currentController = newviewcont;

}
Respondida el 02/03/2009 a las 02:21
fuente por usuario

votos
0

El changeView()método pertenece al viewcontroller. Resolvería el problema de tener la vista al tanto de su controlador (que no debería) y tiene más sentido.

Además, a menos que esté haciendo algo sofisticado changeView()que no se puede hacer utilizando los métodos en un UIViewControllerobjeto, entonces debería usarlo en su lugar, si es necesario implementar su propio método de conmutación de vista, entonces puede extender UIViewController en lugar de implementar parte del ver controlelr en su vista.

mis 2 centavos :)

Respondida el 02/03/2009 a las 01:16
fuente por usuario

votos
-2

Creo que su enfoque es incorrecto. Deberías mirar UINavigationController, creo.

Respondida el 02/03/2009 a las 01:09
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more