Comment ajouter un élément d'interface utilisateur iPhone personnalisé qui n'est pas un composant IB?
-
07-07-2019 - |
Question
J'essaie de créer une application qui utilise l'iPhone MapView (sous Google Code). Je n'arrive pas à comprendre comment intégrer cela dans mon application sans écrire à la main la totalité de l'interface utilisateur, c'est-à-dire ne pas utiliser l'IB du tout.
Comment puis-je utiliser le générateur Interface pour créer tous mes menus et autres, mais ajouter MapView dans? Dois-je modifier MapView pour en faire un composant IB?
Merci!
EDIT:
@pgb
Voici mon code, il n'affiche qu'une UIView vide, j'ai tout connecté du côté de l'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 A ENCORE BIEN GAGNÉ
La solution
Vous pouvez probablement créer toute l'interface dans IB, ajouter un UIView
vide en tant que vue fictive, puis utiliser addSubview:
pour ajouter le MapView
instance dans la hiérarchie des vues.
Votre vue d'espace réservé peut être définie en tant que IBOutlet
. Vous pouvez ensuite ajouter le MapView
à partir de votre instance UIViewController
.
Autres conseils
Dans IB, vous pouvez ajouter un UIView, puis changer le type de vue pour n’importe quel UIView personnalisé. Je suppose que les sous-classes MapView UIView sont identiques à celles de MKMapView ...
J'essaie de créer une application utilisant l'iPhone MapView (sous le code Google).
Pourquoi ne pas utiliser MapKit? Certes, IB est livré avec une MKMapView dans sa bibliothèque.