Ho un UIViewController con il proprio .xib, e voglio usare un UISegmentedControl per visualizzare informazioni diverse nella metà inferiore dello schermo. Ho creato un UIView nel file .xib del contenitore e lo ho collegato a una proprietà UIView denominata detailView
nel contenitore UIViewController.Caricamento .xib in un UIView
Ho quindi creato tre file .xib in IB, uno per la visualizzazione che ciascun segmento deve visualizzare nell'area detailView
.
Sono bloccato perché non so come caricare e scaricare il file .xib appropriato nell'area detailView
. Ecco dove sono:
- (void)segmentValueChanged:(id)sender {
switch ([sender selectedSegmentIndex]) {
case 0:
// Unload whatever is in the detailView UIView and
// Load the AddressView.xib file into it
break;
case 1:
// Unload whatever is in the detailView UIView and
// Load the ContactsView.xib file into it
break;
case 2:
// Unload whatever is in the detailView UIView and
// Load the NotesView.xib file into it
break;
default:
break;
}
}
così come faccio a riempire gli spazi vuoti e scaricare/caricare il detailview UIView correttamente?
Grazie!
--UPDATE--
Il codice in viewDidLoad è ora: - (void) {viewDidLoad [super viewDidLoad];
// Set the default detailView to be address since the default selectedSegmentIndex is 0.
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"AddressView" owner:self options:nil];
// assuming the view is the only top-level object in the nib file (besides File's Owner and First Responder)
UIView *nibView = [nibObjects objectAtIndex:0];
self.detailView = nibView;
self.detailContainerView.autoresizesSubviews = YES;
[self.detailContainerView addSubview:self.detailView];
NSLog(@"self.view is %@", self.view);
NSLog(@"self.detailContainerView is %@",self.detailContainerView);
NSLog(@"self.detailView is %@", self.detailView);
}
E i messaggi di debug sono:
self.view is UIView: 0x3a24d80; frame = (0 0; 320 460); autoresize = RM+BM; layer = CALayer: 0x3a35190
self.detailContainerView is UIView: 0x3a1aea0; frame = (20 57; 280 339); autoresize = W+H; layer = CALayer: 0x3a36b80
self.detailView is UIView: 0x3a24d80; frame = (0 0; 320 460); autoresize = RM+BM; layer = CALayer: 0x3a35190
Grazie!
Non sono abbastanza sicuro di come metterlo insieme. Devo chiamare 'loadNibNamed: owner: options:' per ciascuno dei file .xib?Sarebbe possibile vedere qualche codice approssimativo per avere un'idea di come farlo? Grazie mille! –
Ho aggiunto del codice alla mia risposta. –
Ole, grazie per l'ottimo codice! L'unico problema che sto incontrando è che quando chiamo -loadNibNamed: owner: options il NIB è sovrapposto sopra l'intera vista in cui dovrebbe essere dentro. Sembra che 'self.detailView = nibView;' non ridimensiona la NIB caricata per adattarsi all'interno della detailView impostata in IB. Qualche idea qui? Grazie! –