Adding Previous and Next Car Buttons

You have given the user a way to create cars, and the app shows users car detail. But at the moment, you are always showing the same car. Now it is time to let the user choose which car to view. iOS has lots of ways to do this, and in Chapter 8, “Table Views I: The Basics,” you learn to use one of the most common ones. For now, you use Previous and Next buttons to switch cars.

Previous and Next car buttons work by changing the index of the current car, displayedCarIndex, to a new element in the arrayOfCars. Then they update the displayed info with the routine you wrote earlier. The only real difference between the buttons is that Previous subtracts 1 from the current index, and Next adds 1. Instead of writing ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.