提交 51638b35 编写于 作者: J John Hampton

Creates a Table View

上级 a0d6015a
......@@ -9,13 +9,15 @@
/* Begin PBXBuildFile section */
37154FE2222CBCFE006731A8 /* RatingControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37154FE1222CBCFE006731A8 /* RatingControl.swift */; };
37154FE4222F1EF7006731A8 /* Meal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37154FE3222F1EF7006731A8 /* Meal.swift */; };
37154FE6222F241E006731A8 /* MealTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37154FE5222F241E006731A8 /* MealTableViewCell.swift */; };
3775361422234238005EE5FE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775361322234238005EE5FE /* AppDelegate.swift */; };
3775361622234238005EE5FE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775361522234238005EE5FE /* ViewController.swift */; };
3775361622234238005EE5FE /* MealViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775361522234238005EE5FE /* MealViewController.swift */; };
3775361922234238005EE5FE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3775361722234238005EE5FE /* Main.storyboard */; };
3775361B22234238005EE5FE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3775361A22234238005EE5FE /* Assets.xcassets */; };
3775361E22234238005EE5FE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3775361C22234238005EE5FE /* LaunchScreen.storyboard */; };
3775362922234238005EE5FE /* iOSTemplateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775362822234238005EE5FE /* iOSTemplateTests.swift */; };
3775363422234239005EE5FE /* iOSTemplateUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775363322234239005EE5FE /* iOSTemplateUITests.swift */; };
37EDBD02222F322A00A2190A /* MealTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EDBD01222F322A00A2190A /* MealTableViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -38,9 +40,10 @@
/* Begin PBXFileReference section */
37154FE1222CBCFE006731A8 /* RatingControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingControl.swift; sourceTree = "<group>"; };
37154FE3222F1EF7006731A8 /* Meal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Meal.swift; sourceTree = "<group>"; };
37154FE5222F241E006731A8 /* MealTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MealTableViewCell.swift; sourceTree = "<group>"; };
3775361022234238005EE5FE /* iOSTemplate.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSTemplate.app; sourceTree = BUILT_PRODUCTS_DIR; };
3775361322234238005EE5FE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3775361522234238005EE5FE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
3775361522234238005EE5FE /* MealViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MealViewController.swift; sourceTree = "<group>"; };
3775361822234238005EE5FE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
3775361A22234238005EE5FE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3775361D22234238005EE5FE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
......@@ -51,6 +54,7 @@
3775362F22234239005EE5FE /* iOSTemplateUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSTemplateUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3775363322234239005EE5FE /* iOSTemplateUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSTemplateUITests.swift; sourceTree = "<group>"; };
3775363522234239005EE5FE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
37EDBD01222F322A00A2190A /* MealTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MealTableViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -102,11 +106,13 @@
isa = PBXGroup;
children = (
3775361322234238005EE5FE /* AppDelegate.swift */,
3775361522234238005EE5FE /* ViewController.swift */,
3775361522234238005EE5FE /* MealViewController.swift */,
37154FE3222F1EF7006731A8 /* Meal.swift */,
3775361722234238005EE5FE /* Main.storyboard */,
37154FE5222F241E006731A8 /* MealTableViewCell.swift */,
37154FE1222CBCFE006731A8 /* RatingControl.swift */,
3775361A22234238005EE5FE /* Assets.xcassets */,
37EDBD01222F322A00A2190A /* MealTableViewController.swift */,
3775361C22234238005EE5FE /* LaunchScreen.storyboard */,
3775361F22234238005EE5FE /* Info.plist */,
);
......@@ -262,9 +268,11 @@
buildActionMask = 2147483647;
files = (
37154FE4222F1EF7006731A8 /* Meal.swift in Sources */,
3775361622234238005EE5FE /* ViewController.swift in Sources */,
3775361622234238005EE5FE /* MealViewController.swift in Sources */,
37154FE2222CBCFE006731A8 /* RatingControl.swift in Sources */,
3775361422234238005EE5FE /* AppDelegate.swift in Sources */,
37EDBD02222F322A00A2190A /* MealTableViewController.swift in Sources */,
37154FE6222F241E006731A8 /* MealTableViewCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "meal1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "meal2.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "meal3.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="qli-FJ-LK4">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
......@@ -10,31 +10,75 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Meal Table View Controller-->
<scene sceneID="zgg-br-7lU">
<objects>
<tableViewController id="qli-FJ-LK4" customClass="MealTableViewController" customModule="iOSTemplate" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="90" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="RKG-rd-90S">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="MealTableViewCell" rowHeight="90" id="9Rl-np-g9D" customClass="MealTableViewCell" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="9Rl-np-g9D" id="4Gz-Cp-8Sb">
<rect key="frame" x="0.0" y="0.0" width="375" height="89.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="defaultPhoto" translatesAutoresizingMaskIntoConstraints="NO" id="Ahk-x7-gIe">
<rect key="frame" x="0.0" y="0.0" width="90" height="90"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CD1-k0-BhS">
<rect key="frame" x="98" y="11" width="261" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" fixedFrame="YES" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="mW4-wS-nxh" customClass="RatingControl" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="98" y="35" width="252" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</stackView>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="nameLabel" destination="CD1-k0-BhS" id="a3s-8U-PBl"/>
<outlet property="photoImageView" destination="Ahk-x7-gIe" id="Ywa-p6-yE8"/>
<outlet property="ratingControl" destination="mW4-wS-nxh" id="c6i-Bz-Y3a"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="qli-FJ-LK4" id="CFT-bJ-Dmu"/>
<outlet property="delegate" destination="qli-FJ-LK4" id="YDW-BB-Ku2"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="M5T-rl-Lgo" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-914.39999999999998" y="133.5832083958021"/>
</scene>
<!--Meal View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="iOSTemplate" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="MealViewController" customModule="iOSTemplate" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="l36-fK-dfQ">
<rect key="frame" x="0.0" y="40" width="375" height="438.5"/>
<rect key="frame" x="0.0" y="40" width="375" height="410"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meal Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n9u-9b-TSl">
<rect key="frame" x="144.5" y="0.0" width="86.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter meal name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="DYv-F4-28V">
<rect key="frame" x="0.0" y="28.5" width="375" height="30"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done" enablesReturnKeyAutomatically="YES"/>
</textField>
<imageView contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" placeholderIntrinsicWidth="320" placeholderIntrinsicHeight="320" image="defaultPhoto" translatesAutoresizingMaskIntoConstraints="NO" id="Rhj-yY-68e">
<rect key="frame" x="27.5" y="66.5" width="320" height="320"/>
<rect key="frame" x="27.5" y="38" width="320" height="320"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="width" secondItem="Rhj-yY-68e" secondAttribute="height" multiplier="1:1" id="ACo-ke-FCa"/>
......@@ -44,7 +88,7 @@
</connections>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="5FE-RR-A0X" customClass="RatingControl" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="61.5" y="394.5" width="252" height="44"/>
<rect key="frame" x="61.5" y="366" width="252" height="44"/>
</stackView>
</subviews>
<constraints>
......@@ -61,7 +105,6 @@
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="mealNameLabel" destination="n9u-9b-TSl" id="6WN-5O-Vth"/>
<outlet property="nameTextField" destination="DYv-F4-28V" id="GJa-MY-QZF"/>
<outlet property="photoImageView" destination="Rhj-yY-68e" id="4Ye-IM-GYI"/>
<outlet property="ratingControl" destination="5FE-RR-A0X" id="blZ-Gl-7t1"/>
......
//
// MealTableViewCell.swift
// iOSTemplate
//
// Created by John Hampton on 3/5/19.
//
import UIKit
class MealTableViewCell: UITableViewCell {
// MARK: Properties
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var photoImageView: UIImageView!
@IBOutlet weak var ratingControl: RatingControl!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
//
// MealTableViewController.swift
// iOSTemplate
//
// Created by John Hampton on 3/5/19.
//
import UIKit
class MealTableViewController: UITableViewController {
// MARK: Properties
var meals = [Meal]()
override func viewDidLoad() {
super.viewDidLoad()
// Load the sample data.
loadSampleMeals()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return meals.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "MealTableViewCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? MealTableViewCell else {
fatalError("The dequeued cell is not an instance of MealTableViewCell.")
}
// Fetches the appropriate meal for the data source layout.
let meal = meals[indexPath.row]
cell.nameLabel.text = meal.name
cell.photoImageView.image = meal.photo
cell.ratingControl.rating = meal.rating
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
// MARK: Private Methods
private func loadSampleMeals() {
let photo1 = UIImage(named: "meal1")
let photo2 = UIImage(named: "meal2")
let photo3 = UIImage(named: "meal3")
guard let meal1 = Meal(name: "Caprese Salad", photo: photo1, rating: 4) else {
fatalError("Unable to instantiate meal1")
}
guard let meal2 = Meal(name: "Chicken and Potatoes", photo: photo2, rating: 5) else {
fatalError("Unable to instantiate meal2")
}
guard let meal3 = Meal(name: "Pasta with Meatballs", photo: photo3, rating: 3) else {
fatalError("Unable to instantiate meal2")
}
meals += [meal1, meal2, meal3]
}
}
//
// ViewController.swift
// MealViewController.swift
// iOSTemplate
//
// Created by John Hampton on 2/24/19.
......@@ -7,11 +7,10 @@
import UIKit
class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
class MealViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// MARK: Properties
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var mealNameLabel: UILabel!
@IBOutlet weak var photoImageView: UIImageView!
@IBOutlet weak var ratingControl: RatingControl!
......@@ -30,7 +29,6 @@ class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerContro
}
func textFieldDidEndEditing(_ textField: UITextField) {
mealNameLabel.text = textField.text
}
//MARK: UIImagePickerControllerDelegate
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册