Part 3, Episode 17, Use CareKit to make a contact page
In this episode, I want to show you how to use another feature from CareKit, which allows you to have a contact page inside your app for quick access if your user needs to contact you.
Let’s make one last feature done together, Open SceneDelegate from Project Navigator right after // Create Contact Page add these codes:
makeContacts()
let contactViewController = OCKListViewController()
contactViewController.appendViewController(OCKDetailedContactViewController(contactID: "contact.emad", storeManager: storeManager), animated: false)
contactViewController.title = "Contact"
contactViewController.tabBarItem = UITabBarItem(
title: "Contact",
image: UIImage(systemName: "list.bullet"),
tag: 1
)
Here you used the prepared function to make the contacts and store them in the StoreManager. Next, you initiate an OCKListViewController and then append one OCKDetailedContactViewController and use the contact id I prepared for you on that function. The last thing is you styled it. Now it’s time to use that ViewController inside of the tab bar.
let contactTab = UINavigationController(rootViewController: contactViewController)
Here, you create a navigation controller and add the contact view controller as a root.
rootController.setViewControllers([planTab, overviewTab, contactTab], animated: false)
Furthermore, you modify the list of tabs by adding the contact tab. If you scroll to the end, you see what I prepared for you; it’s an OCKContact object with some information as input.
Build and run the project and navigate to the contact tab to see what you’ve made.
If you want to see another style of Contact page, you can easily change the viewController type from OCKDetailedContactViewController to the OCKSimpleContactViewController and then build and run the project to see does this looks; I like this one better because it’s more Apple style :)