Come aggiungere un elemento dell'interfaccia utente iPhone personalizzata che non sia un componente IB?
-
07-07-2019 - |
Domanda
Sto cercando di creare un'applicazione che utilizza iPhone MapView (sotto Google Code). Non riesco a capire come integrare questa cosa nella mia applicazione senza scrivere a mano l'intera UI, cioè non usare affatto l'IB.
Come posso usare Interface Builder per creare tutti i miei menu e simili ma aggiungere MapView in? Devo modificare MapView per renderlo un componente IB?
Grazie!
EDIT:
@pgb
Ecco il mio codice, mostra ancora una UIView vuota, ho collegato tutto sul lato IB.
//
// NewTestViewController.h
// NewTest
//
#import <UIKit/UIKit.h>
@interface NewTestViewController : UIViewController {
UIView* mapPlaceholder;
}
@property (nonatomic, retain) IBOutlet UIView* mapPlaceholder;
@end
//
// NewTestViewController.m
// NewTest
//
#import "NewTestViewController.h"
#import "MapView.h"
@implementation NewTestViewController
@synthesize mapPlaceholder;
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
MapView *mapView = [[[MapView alloc] initWithFrame:
[[UIScreen mainScreen] applicationFrame]] autorelease];
[mapPlaceholder addSubview:mapView];
}
return self;
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[mapPlaceholder.subviews release];
[super dealloc];
}
@end
NEVERMIND LO HA FATTO PERCHÉ PBG
Soluzione
Probabilmente puoi creare l'intera interfaccia in IB, aggiungere un UIView
vuoto come vista segnaposto, quindi utilizzare addSubview:
per aggiungere MapView
istanza nella gerarchia della vista.
La tua vista segnaposto può essere definita come IBOutlet
, quindi puoi aggiungere MapView
dalla tua istanza UIViewController
.
Altri suggerimenti
In IB puoi aggiungere un UIView e quindi cambiare il tipo di vista in qualsiasi UIView personalizzato - suppongo che UIView subclasse MapView proprio come fa MKMapView ...
Sto cercando di creare un'applicazione che utilizza iPhone MapView (sotto Google Code).
Perché non usare MapKit? Sicuramente IB viene fornito con un MKMapView nella sua libreria.