diff --git a/FirstApp.xcodeproj/project.pbxproj b/FirstApp.xcodeproj/project.pbxproj index b4d4118..c8a8561 100644 --- a/FirstApp.xcodeproj/project.pbxproj +++ b/FirstApp.xcodeproj/project.pbxproj @@ -10,8 +10,7 @@ 9C5BCFA62293831400174013 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5BCFA52293831400174013 /* AppDelegate.swift */; }; 9C5BCFAD2293831500174013 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9C5BCFAC2293831500174013 /* Assets.xcassets */; }; 9C5BCFB02293831500174013 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C5BCFAE2293831500174013 /* LaunchScreen.storyboard */; }; - 9CC6713922938BB200B7E83E /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CC6713722938BB200B7E83E /* FirstViewController.swift */; }; - 9CC6713A22938BB200B7E83E /* FirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9CC6713822938BB200B7E83E /* FirstViewController.xib */; }; + 9CC6713922938BB200B7E83E /* MyTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CC6713722938BB200B7E83E /* MyTableViewController.swift */; }; B1D4EC9EF6A7F164CD1D6C4D /* Pods_FirstApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8C1B7DB637C4693D9E3413F /* Pods_FirstApp.framework */; }; /* End PBXBuildFile section */ @@ -22,8 +21,7 @@ 9C5BCFAC2293831500174013 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 9C5BCFAF2293831500174013 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 9C5BCFB12293831500174013 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 9CC6713722938BB200B7E83E /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; - 9CC6713822938BB200B7E83E /* FirstViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FirstViewController.xib; sourceTree = ""; }; + 9CC6713722938BB200B7E83E /* MyTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyTableViewController.swift; sourceTree = ""; }; B4122CEF4489A7F5BBF7FD8D /* Pods-FirstApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FirstApp.release.xcconfig"; path = "Target Support Files/Pods-FirstApp/Pods-FirstApp.release.xcconfig"; sourceTree = ""; }; C8C1B7DB637C4693D9E3413F /* Pods_FirstApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FirstApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -73,8 +71,7 @@ 9C5BCFAC2293831500174013 /* Assets.xcassets */, 9C5BCFAE2293831500174013 /* LaunchScreen.storyboard */, 9C5BCFB12293831500174013 /* Info.plist */, - 9CC6713722938BB200B7E83E /* FirstViewController.swift */, - 9CC6713822938BB200B7E83E /* FirstViewController.xib */, + 9CC6713722938BB200B7E83E /* MyTableViewController.swift */, ); path = FirstApp; sourceTree = ""; @@ -149,7 +146,6 @@ buildActionMask = 2147483647; files = ( 9C5BCFB02293831500174013 /* LaunchScreen.storyboard in Resources */, - 9CC6713A22938BB200B7E83E /* FirstViewController.xib in Resources */, 9C5BCFAD2293831500174013 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -209,7 +205,7 @@ buildActionMask = 2147483647; files = ( 9C5BCFA62293831400174013 /* AppDelegate.swift in Sources */, - 9CC6713922938BB200B7E83E /* FirstViewController.swift in Sources */, + 9CC6713922938BB200B7E83E /* MyTableViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FirstApp/AppDelegate.swift b/FirstApp/AppDelegate.swift index 8b8961d..cd8aab6 100644 --- a/FirstApp/AppDelegate.swift +++ b/FirstApp/AppDelegate.swift @@ -13,18 +13,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - var navigationController: UINavigationController? - var firstViewController: FirstViewController? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. window = UIWindow() - self.firstViewController = FirstViewController(nibName: "FirstViewController", bundle: nil) - self.navigationController = UINavigationController(rootViewController: self.firstViewController!) + let tableViewController = MyTableViewController() + let navigationController = UINavigationController(rootViewController: tableViewController) - self.window?.rootViewController = self.navigationController - self.window?.makeKeyAndVisible() + window?.rootViewController = navigationController + window?.makeKeyAndVisible() return true } diff --git a/FirstApp/FirstViewController.swift b/FirstApp/FirstViewController.swift deleted file mode 100644 index ea77108..0000000 --- a/FirstApp/FirstViewController.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// FirstViewController.swift -// FirstApp -// -// Created by ahmed.aly on 5/20/19. -// Copyright © 2019 yeetsies. All rights reserved. -// - -import UIKit - -class FirstViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - - } -} diff --git a/FirstApp/FirstViewController.xib b/FirstApp/FirstViewController.xib deleted file mode 100644 index 5abb308..0000000 --- a/FirstApp/FirstViewController.xib +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FirstApp/MyTableViewController.swift b/FirstApp/MyTableViewController.swift new file mode 100644 index 0000000..a91f166 --- /dev/null +++ b/FirstApp/MyTableViewController.swift @@ -0,0 +1,90 @@ +// +// FirstViewController.swift +// FirstApp +// +// Created by ahmed.aly on 5/20/19. +// Copyright © 2019 yeetsies. All rights reserved. +// + +import UIKit + +class MyTableViewController: UITableViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + navigationItem.title = "My TableView" + tableView.register(MyCell.self, forCellReuseIdentifier: "cellId") + tableView.register(Header.self, forHeaderFooterViewReuseIdentifier: "headerId") + tableView.sectionHeaderHeight = 50 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 5 + } + + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + return tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) + } + + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + return tableView.dequeueReusableHeaderFooterView(withIdentifier: "headerId") + } +} + +class Header: UITableViewHeaderFooterView { + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + setUpViews() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + let nameLabel: UILabel = { + let label = UILabel() + label.text = "My Header" + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.boldSystemFont(ofSize: 14) + return label + }() + + func setUpViews() { + addSubview(nameLabel) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]|", options: [], + metrics: nil, views: ["v0": nameLabel])) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-16-[v0]-16-|", options: [], + metrics: nil, views: ["v0": nameLabel])) + + } +} + +class MyCell: UITableViewCell { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setUpViews() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + let nameLabel: UILabel = { + let label = UILabel() + label.text = "Sample Item" + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.boldSystemFont(ofSize: 14) + return label + }() + + func setUpViews() { + addSubview(nameLabel) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]|", options: [], + metrics: nil, views: ["v0": nameLabel])) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-16-[v0]-16-|", options: [], + metrics: nil, views: ["v0": nameLabel])) + + } +}