Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions FirstApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -22,8 +21,7 @@
9C5BCFAC2293831500174013 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9C5BCFAF2293831500174013 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9C5BCFB12293831500174013 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9CC6713722938BB200B7E83E /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = "<group>"; };
9CC6713822938BB200B7E83E /* FirstViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FirstViewController.xib; sourceTree = "<group>"; };
9CC6713722938BB200B7E83E /* MyTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyTableViewController.swift; sourceTree = "<group>"; };
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 = "<group>"; };
C8C1B7DB637C4693D9E3413F /* Pods_FirstApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FirstApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -149,7 +146,6 @@
buildActionMask = 2147483647;
files = (
9C5BCFB02293831500174013 /* LaunchScreen.storyboard in Resources */,
9CC6713A22938BB200B7E83E /* FirstViewController.xib in Resources */,
9C5BCFAD2293831500174013 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -209,7 +205,7 @@
buildActionMask = 2147483647;
files = (
9C5BCFA62293831400174013 /* AppDelegate.swift in Sources */,
9CC6713922938BB200B7E83E /* FirstViewController.swift in Sources */,
9CC6713922938BB200B7E83E /* MyTableViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
10 changes: 4 additions & 6 deletions FirstApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 0 additions & 17 deletions FirstApp/FirstViewController.swift

This file was deleted.

36 changes: 0 additions & 36 deletions FirstApp/FirstViewController.xib

This file was deleted.

90 changes: 90 additions & 0 deletions FirstApp/MyTableViewController.swift
Original file line number Diff line number Diff line change
@@ -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: [],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using a visual format a preference over using anchors?

metrics: nil, views: ["v0": nameLabel]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-16-[v0]-16-|", options: [],
metrics: nil, views: ["v0": nameLabel]))

}
}