0
回答
IOS百度地图 多个BMKMapView对象问题
注册华为云得mate10,2.9折抢先购!>>>   

有两个XIB文件,主视图称为A,新建的XIB称为B,分别设置个百度mapView,当按按钮‘路线时’,进入B页面,视图没问题,可是从B页面返回后,A页面的视图花掉了,是怎么回事??下面给出详细的代码,如果有知道的,还望高手指点,谢谢!!!

说明:为说明情况,故意在两个XIB文件中把百度地图视图设置的大小和位置不同

一、初始页面:


二、按 “路线”按钮(自定义的)进入B页面中的视图

三、按 “Back” 按钮返回到初始页面A的视图,这时候地图花掉了,是怎么回事?

下面是详细代码:

AppDelegate.h中的文件:

01 #import <UIKit/UIKit.h>
02 #import "BMapKit.h"
03  
04 @class ViewController;
05  
06 @interface AppDelegate : UIResponder <UIApplicationDelegate,BMKGeneralDelegate>
07 {
08     BMKMapManager *_mapManager;
09 }
10  
11 @property (strong, nonatomic) UIWindow *window;
12  
13 @property (strong, nonatomic) ViewController *viewController;
14  
15 @end


AppDelegate.m中的文件:

01 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
02 {
03     _mapManager = [[BMKMapManager alloc] init];
04     BOOL ret = [_mapManager start:@"8C530589D4AFB1A344A9384E92B4FC377E3F9FAC"generalDelegate:nil];
05     if (!ret) {
06         NSLog(@"manager start failed!");
07     }
08      
09     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
10     // Override point for customization after application launch.
11     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController"bundle:nil];
12     UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:self.viewController];
13     self.window.rootViewController = controller;
14     [self.window makeKeyAndVisible];
15     return YES;
16 }

ViewController.h中的文件:

01 #import <UIKit/UIKit.h>
02 #import "BMapKit.h"
03 #import "SecondViewController.h"
04  
05 @interfaceViewController : UIViewController<BMKMapViewDelegate,BMKSearchDelegate>
06 {
07     BMKMapView *mapView;
08     UIButton *button1;
09     UIButton *button2;
10     UIButton *button3;
11     UIButton *button4;
12     BMKSearch *search;
13     //    NSString *strCity;
14     NSString *userLocation;
15     CLLocationCoordinate2D userPt;
16 }
17 @property (weak, nonatomic) IBOutlet BMKMapView *mapView2;
18  
19 @end


View  ViewController.m中的文件:
01 - (void)viewDidLoad
02 {
03     [super viewDidLoad];
04     // Do any additional setup after loading the view, typically from a nib.
05     mapView2.showsUserLocation = YES;
06      
07     button2 = [UIButton buttonWithType:UIButtonTypeCustom];
08     button2.frame = CGRectMake(60, 110 - 44, 100, 35);
09     button2.backgroundColor = [UIColor grayColor];
10     button2.alpha = 0.8;
11     [button2 setImage:[UIImage imageNamed:@"222.png"] forState:UIControlStateHighlighted];
12     [button2 setTitle:@"路线" forState:UIControlStateNormal];
13     [button2 addTarget:self action:@selector(toRouteView) forControlEvents:UIControlEventTouchUpInside];
14     [self.view addSubview:button2];
15      
16 }
17  
18 -(void)toRouteView
19 {
20     SecondViewController *secondView = [[SecondViewController alloc] init];
21     [self.navigationController pushViewController:secondView animated:YES];
22 }

iOS
举报
yuankai66
发帖于5年前 0回/2K+阅
顶部