(Part 4 of 5)
This is the fourth part of our tvOS tutorial. Please check out the previous Article to know more about this series.
Before moving forward, I would like to appreciate the work you have done so far.
Note: Even though you are running on your local web server, you could have put this on a live web server or perhaps hooked up to a database.
Explanation of the code:
- A TVML document starts off by enclosing its contents with <document>.
- Next, we define the template, in our case its <alertTemplate>.
- Within the template you can further design it with a title, description, button and much more. To check all the designing elements available, click here.
Save your file, and build and run. You should see a button associated with your alert view. Yippee., TVML made easy!
Note: The amount of elements you can put within a template vary depending on the specific template. For instance, a loadingTemplate does not allow any buttons. A list of each template’s capabilities can be found here.
In this section, we’ll spend time splitting the logic into different classes for better reusability.
Explanation to the code:
- DOMParser — It is a class that can convert TVML string to an Objext-Oriented Presentation. It is created only once and is reiused any number of times. You then add lines to parse a TVML string and return the document.
- modalDialogPresenter — This method takes a TVML document and presents it modally on screen.
- pushDocument — This method pushes a TVM L document onto the navigation stack
Later in this tutorial, we’ll have the Presenter class manage the cell selection as-well. Replace the current implementation of App.onLaunch with the following code:
Explanation of code:
- The error is handled here, we have added an alert incase of any errors.