iosobjective-ctangram

Tangram self.view downcasting to TGMapView. Where is self.view assigned?


In Tangram's current demo app, the below method is defined in 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;
}

The first thing that happens, after super, is a downcast of the self.view to be of type TGMapView. Two questions that might have the related answers:

  1. Generally, where is self.view assigned a value?

  2. With what init method is a view or custom view created?


After further research, I found this on the apple docs. It seems to imply that custom UIView must have these inits. It isn't clear to me why two different inits would be required, but I can assume that apple uses one or both to initialize the view.


Solution

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

    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).