📱 Master–Detail Template, Drill-Down Menus & Navigation (iOS – Xcode)
✅ 1. Definition
🔹 Master–Detail Template
A Master–Detail app is a common iOS design pattern where:
- Master View → shows a list of items
- Detail View → shows full information about the selected item
👉 Example:
- Email app (Inbox → Email content)
- Contacts app (List → Contact details)
🔹 Drill-Down Menu
A drill-down menu is a navigation style where the user:
- Starts from a list (main screen)
- Taps an item
- Moves deeper into another screen with more details
👉 It creates a hierarchical navigation flow
🔹 Navigation
Navigation is the process of moving between different screens (View Controllers) using:
- Navigation Controller
- Segues
- Push / Pop transitions
🧠 2. Key Concepts
🔹 UINavigationController
- Manages a stack of view controllers
- Controls navigation flow
🔹 Navigation Stack
- First screen = root view controller
- New screens are pushed on top
Root → Screen 1 → Screen 2 → Screen 3
🔹 Push & Pop
| Action |
Meaning |
| Push |
Move to next screen |
| Pop |
Go back to previous screen |
🏗️ 3. Master–Detail Structure
Master View (List)
↓
User selects item
↓
Detail View (Information)
⚙️ 4. How Master–Detail Works
🔹 Step 1: Master View (Table View)
- Displays list of items
- Uses
UITableView
let items = ["iPhone", "iPad", "MacBook"]
🔹 Step 2: Select Item
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedItem = items[indexPath.row]
}
🔹 Step 3: Navigate to Detail View
Using Storyboard Segue:
- Control + Drag → “Show (Push)”
OR programmatically:
let vc = storyboard?.instantiateViewController(withIdentifier: "DetailVC") as! DetailViewController
vc.selectedItem = items[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
🔹 Step 4: Display Detail Data
override func viewDidLoad() {
super.viewDidLoad()
detailLabel.text = selectedItem
}
🔄 5. Drill-Down Navigation Flow
List Screen
↓ tap
Category Screen
↓ tap
Detail Screen
👉 Each selection goes deeper into the app structure.
📊 6. Diagram Description (for Exams)
Draw:
Master (List)
↓
Detail (Info)
↓
More Detail (Optional Drill Down)
OR Navigation Stack:
Root → Screen 1 → Screen 2 → Screen 3
🧭 7. Navigation Methods in iOS
🔹 1. Push Navigation
navigationController?.pushViewController(vc, animated: true)
🔹 2. Pop Navigation
navigationController?.popViewController(animated: true)
🔹 3. Pop to Root
navigationController?.popToRootViewController(animated: true)
💡 8. Example App
🎯 Product App
- Master: Product list
- Detail: Product information
Flow:
- User selects “iPhone”
- Moves to detail screen
- Shows specs, price, description
📌 9. Important Rules / Tips
- Always embed in Navigation Controller
- Use segues or push navigation
- Pass data before navigating
- Maintain clean hierarchy
- Use drill-down only for related screens
⚠️ 10. Common Mistakes
- ❌ Not using Navigation Controller
- ❌ Forgetting to pass data to detail view
- ❌ Wrong storyboard identifiers
- ❌ Losing navigation stack
- ❌ Overcomplicated navigation flow
🧠 11. Best Practices
- Keep master list simple
- Use clear navigation hierarchy
- Pass only necessary data
- Use reusable view controllers
- Maintain consistent UI flow
📝 12. Likely Exam Questions
- What is a Master–Detail application?
- Explain drill-down navigation.
- What is UINavigationController?
- Differentiate push and pop navigation.
- How do you pass data between view controllers?
- Explain navigation stack with diagram.
- Write code to navigate to detail screen.
- What is the use of Master view in iOS apps?
📚 13. Quick Revision Summary
-
Master View → list of items
-
Detail View → selected item info
-
Drill-down → step-by-step deeper navigation
-
Uses:
- Navigation Controller
- Push / Pop methods
-
Navigation stack manages screens
-
Very common in:
- Settings apps
- Email apps
- Product catalogs