1

在 Tangram 的当前演示应用程序中,以下方法在 MapViewController.m 中定义

- (void)viewDidLoad
{
    [super viewDidLoad];

    TGMapView *mapView = (TGMapView *)self.view;
    mapView.mapViewDelegate = self;
    mapView.gestureDelegate = self;
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
}

在 super 之后发生的第一件事是将 self.view 向下转换为 TGMapView 类型。可能有相关答案的两个问题:

  1. 一般来说,self.view 在哪里赋值?

  2. 使用什么 init 方法创建视图或自定义视图?


经过进一步研究,我在苹果文档上找到了这个。这似乎暗示自定义 UIView 必须具有这些初始化。我不清楚为什么需要两个不同的初始化,但我可以假设苹果使用一个或两个来初始化视图。

4

1 回答 1

2

There are several ways to specify a view for view controller (More details in "View Management" section of UIViewController documentation):

  • In a storyboard
  • In a nib file
  • Overriding controller's loadView method and create view there explicitly.

Demo app you've linked to uses storyboards to create UI and custom class for a view is specified in Main_iPhone.storyboard (and Main_iPad.storyboard).

于 2018-11-26T17:05:04.120 回答