rimozione della vista da un controller di visualizzazione
-
03-07-2019 - |
Domanda
Voglio rimuovere la subview corrente (aggiunta a Index: 0) dal mio controller della vista radice e inserire una nuova vista al suo posto.
Attualmente posso trovare solo frammenti di codice che mostrano come scaricare una vista usando removeFromSuperView, che richiede di sapere quale vista viewcontroller è attualmente caricata.
L'unica altra cosa da notare è che ho un'altra sottoview inserita nella vista rootcontroller che non voglio scaricare. Quindi il codice che rimuove tutte le visualizzazioni secondarie non è adeguato
Grazie,
m
if(self.firstscr == nil)
{
firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
self.firstscr = f;
[f release];
}
///This is my attempt at getting to the currently loaded view :P
[[self.view subviews atIndex:0].view removeFromSuperView];
[self.view insertSubview:firstscr.view atIndex:0];
Soluzione
Ecco come farlo (l'ho capito, Yey me!)
if(self.firstscr == nil)
{
firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
self.firstscr = f;
[f release];
}
//Remove whatever view is currently loaded at index 0, this index is only to be used by "page" views
UIView *v = [self.view.subviews objectAtIndex:0];
[v removeFromSuperview];
[self.view insertSubview:firstscr.view atIndex:0];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow