【问题标题】:Storyboard map not displaying or spanning specified region故事板地图未显示或跨越指定区域
【发布时间】:2014-06-14 12:55:09
【问题描述】:

我一直在开发一个程序,在该程序中单击 uisplitview 中的单元格时,会加载以特定区域为中心的地图。但是,这很好用。因为有了新功能,所以需要将我的 xib 放入我的故事板中。现在,当我单击单元格以调用我的地图时...地图确实加载了,但它没有以它应该位于的区域为中心,我不知道为什么,因为该代码似乎正在运行(添加断点)

以下是选择“自然”字段时运行的代码。 (注释代码是我的原始代码...注意我传入的变量)下面是要sergue的代码

最后,我不确定为什么当我使用[self performSegueWithIdentifier:@"countryMap" sender:self]; 时地图无法按预期工作,但在我使用时却可以工作

mapViewController *mapView=[[mapViewController    alloc]initWithNibName:@"mapViewController" bundle:nil location:0 option:@"na"];
      [self.navigationController pushViewController:mapView animated:NO];

唯一的区别是当我使用 sergue 时,init 方法(代码发布在底部)不运行。但正如我在添加断点之前所说的那样,viewDidLoad 中的代码确实可以运行

if ( ([receivedRainObject isEqualToString:@"Natural"])) {

 //    mapViewController *mapView=[[mapViewController      alloc]initWithNibName:@"mapViewController" bundle:nil location:0 option:@"na"];
      //      [self.navigationController pushViewController:mapView animated:NO];
 [self performSegueWithIdentifier:@"countryMap" sender:self];   
        }

然后在所说的 Sergue 中注意我是如何再次传入这些变量的。 (我想知道在这里这样做是否有问题

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"countryMap"]) {
         mapViewController *transferViewController=segue.destinationViewController;
        transferViewController.location=0;
        transferViewController.option=@"na";

    }
}

然后在视图中加载了地图 位置确实评估为 0,断点显示所有这些代码都在逐步执行,但我提供的坐标区域不是显示的内容。(跨度或区域) (但是当我调用我的旧 xib 时它工作正常)

- (void)viewDidLoad
{
    [super viewDidLoad];
   {

    // Do any additional setup after loading the view from its nib.

    if (location==0)
    {

         CLLocationCoordinate2D location1;
         location1.latitude=(double)15.435786;
         location1.longitude=(double)-61.318447;


                    MKCoordinateRegion region;
                    MKCoordinateSpan span;
                    span.latitudeDelta=0.50;
                    span.longitudeDelta=0.40;
                    region.span=span;
                    region.center= location1;

                    [mapView setRegion:region animated:TRUE];
                    [mapView regionThatFits:region];
               }
}

我的地图视图的初始化

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil location:(int)num option:(NSString *)row
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.location=num;
        self.option=row;

    }
    return self;
}

【问题讨论】:

  • 地图显示的是哪个区域?你检查过 mapView 不是 nil 吗?
  • @rdelmar 它正在加载美国地图。在 [mapView regionThatFits:region] 线上放置了一个断点;它确实是零。当我以旧方式加载地图时,它不是零
  • mapView 是 IBOutlet 吗?你在 IB 上挂了吗?
  • @rdelmar 为什么我做到了。它是一个 IBOutlet。我仍然在故事板中看到它你
  • 那么,如果 mapView 为 nil,但 IBOutlet 已连接(不只是存在)在情节提要中,您会说日志?

标签: ios objective-c mapkit


【解决方案1】:

鉴于您的 cmets,唯一合乎逻辑的解释是 mapView 的 IBOutlet 未连接。如果将视图从 xib 文件移动到情节提要,则任何连接到文件所有者的 IBOutlets 都不会与视图一起转移,因为情节提要中不存在文件的所有者。因此,您需要重新制作连接到文件所有者的所有插座。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多