diff --git a/shop2/Controller/ViewController.swift b/shop2/Controller/ViewController.swift index 3db15d4098d0a5a76fb140c2f1a4f0b4906ca7d2..8453c6f6a8085462028d93acd35a7f69c024a360 100644 --- a/shop2/Controller/ViewController.swift +++ b/shop2/Controller/ViewController.swift @@ -8,6 +8,7 @@ import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { + @IBOutlet var tableView : UITableView! private let productService = productController() var productList = [productDetails]() @@ -23,6 +24,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour Task { do { try await fetchProducts() + print("aye") } catch { print("Failed to fetch products: \(error)") } @@ -32,11 +34,12 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour func fetchProducts() async throws { do { + print("hey") self.productList = try await productService.fetchProductDetails() navigationItem.title = "Products" tableView.rowHeight = 120 - + print("yo") tableView.reloadData() } catch { print("Error fetching products: \(error)") @@ -52,6 +55,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour } guard let data = data, let image = UIImage(data: data) else { completion(nil) + return } completion(image) @@ -64,7 +68,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if let vc = storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController{ + if let vc = storyboard?.instantiateViewController(withIdentifier: "third") as? SecondViewController{ let product = productList[indexPath.row] vc.id = String(product.id) diff --git a/shop2/View/Base.lproj/Main.storyboard b/shop2/View/Base.lproj/Main.storyboard index 32a8ac233c3209e8cf5626a1924cd7421c580bac..7b9722f3b171abe90d1c7ca206db5d29c34101bc 100644 --- a/shop2/View/Base.lproj/Main.storyboard +++ b/shop2/View/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="PNW-T3-Tjy"> - <device id="retina6_72" orientation="portrait" appearance="light"/> + <device id="retina4_0" orientation="portrait" appearance="light"/> <dependencies> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> @@ -13,18 +13,18 @@ <objects> <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="shop2" customModuleProvider="target" sceneMemberID="viewController"> <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> - <rect key="frame" x="0.0" y="0.0" width="430" height="932"/> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="mW4-X5-ZnP"> - <rect key="frame" x="0.0" y="103" width="430" height="795"/> + <rect key="frame" x="0.0" y="64" width="320" height="504"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> <prototypes> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="CustomTableViewCell" rowHeight="125" id="Uss-Jf-ehf" customClass="CustomTableViewCell" customModule="shop2" customModuleProvider="target"> - <rect key="frame" x="0.0" y="50" width="430" height="125"/> + <rect key="frame" x="0.0" y="50" width="320" height="125"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Uss-Jf-ehf" id="xWa-T9-hUP"> - <rect key="frame" x="0.0" y="0.0" width="430" height="125"/> + <rect key="frame" x="0.0" y="0.0" width="320" height="125"/> <autoresizingMask key="autoresizingMask"/> <subviews> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="F25-4H-xyF"> @@ -35,13 +35,13 @@ </constraints> </imageView> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ATq-0K-GJG"> - <rect key="frame" x="120" y="21" width="300" height="18"/> + <rect key="frame" x="120" y="21" width="190" height="18"/> <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="15"/> <nil key="textColor"/> <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gin-0N-e4L"> - <rect key="frame" x="320" y="84.666666666666671" width="80" height="19.333333333333329"/> + <rect key="frame" x="214" y="84.5" width="80" height="19.5"/> <color key="backgroundColor" systemColor="systemRedColor"/> <constraints> <constraint firstAttribute="width" constant="80" id="s9L-Si-uh9"/> @@ -94,7 +94,7 @@ <navigationController automaticallyAdjustsScrollViewInsets="NO" id="PNW-T3-Tjy" sceneMemberID="viewController"> <toolbarItems/> <navigationBar key="navigationBar" contentMode="scaleToFill" id="GjD-HL-4I5"> - <rect key="frame" x="0.0" y="59" width="430" height="44"/> + <rect key="frame" x="0.0" y="20" width="320" height="50"/> <autoresizingMask key="autoresizingMask"/> </navigationBar> <nil name="viewControllers"/> @@ -111,18 +111,18 @@ <objects> <viewController storyboardIdentifier="SecondViewController" id="TWg-l6-YWE" customClass="SecondViewController" customModule="shop2" customModuleProvider="target" sceneMemberID="viewController"> <view key="view" contentMode="scaleToFill" id="GUj-Jp-Qny"> - <rect key="frame" x="0.0" y="0.0" width="430" height="932"/> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="9ZW-KG-i2N"> - <rect key="frame" x="115" y="213" width="200" height="200"/> + <rect key="frame" x="60" y="174" width="200" height="200"/> <constraints> <constraint firstAttribute="width" constant="200" id="BQD-15-GMq"/> <constraint firstAttribute="height" constant="200" id="PzM-aO-JLT"/> </constraints> </imageView> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Product Name" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="250" translatesAutoresizingMaskIntoConstraints="NO" id="RUe-aa-ICe"> - <rect key="frame" x="90" y="453.66666666666669" width="250" height="19.333333333333314"/> + <rect key="frame" x="35" y="414.5" width="250" height="19.5"/> <constraints> <constraint firstAttribute="width" constant="250" id="b69-cb-NSX"/> </constraints> @@ -131,10 +131,10 @@ <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hls-Ox-2vm"> - <rect key="frame" x="175" y="502" width="80" height="21"/> + <rect key="frame" x="120" y="463" width="80" height="21"/> <color key="backgroundColor" systemColor="systemRedColor"/> <constraints> - <constraint firstAttribute="width" constant="80" id="PpO-l2-pkX"/> + <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="80" id="PpO-l2-pkX"/> </constraints> <fontDescription key="fontDescription" type="system" pointSize="17"/> <nil key="textColor"/> @@ -144,13 +144,11 @@ <viewLayoutGuide key="safeArea" id="EgF-Md-b6Z"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> <constraints> - <constraint firstItem="EgF-Md-b6Z" firstAttribute="trailing" secondItem="9ZW-KG-i2N" secondAttribute="trailing" constant="115" id="5n3-4T-7XX"/> <constraint firstItem="hls-Ox-2vm" firstAttribute="centerX" secondItem="GUj-Jp-Qny" secondAttribute="centerX" id="HXZ-Hw-Wfr"/> - <constraint firstItem="EgF-Md-b6Z" firstAttribute="trailing" secondItem="RUe-aa-ICe" secondAttribute="trailing" constant="90" id="HZQ-ik-d18"/> - <constraint firstItem="RUe-aa-ICe" firstAttribute="leading" secondItem="EgF-Md-b6Z" secondAttribute="leading" constant="90" id="WEw-d5-53a"/> + <constraint firstItem="RUe-aa-ICe" firstAttribute="centerX" secondItem="GUj-Jp-Qny" secondAttribute="centerX" id="KqY-xF-LSy"/> + <constraint firstItem="9ZW-KG-i2N" firstAttribute="centerX" secondItem="GUj-Jp-Qny" secondAttribute="centerX" id="cBZ-Mm-rZ9"/> <constraint firstItem="hls-Ox-2vm" firstAttribute="bottom" secondItem="RUe-aa-ICe" secondAttribute="bottom" constant="50" id="frt-WE-J3I"/> <constraint firstItem="RUe-aa-ICe" firstAttribute="bottom" secondItem="9ZW-KG-i2N" secondAttribute="bottom" constant="60" id="hiz-LH-AQY"/> - <constraint firstItem="9ZW-KG-i2N" firstAttribute="leading" secondItem="EgF-Md-b6Z" secondAttribute="leading" constant="115" id="nXN-kU-F8n"/> <constraint firstItem="9ZW-KG-i2N" firstAttribute="top" secondItem="EgF-Md-b6Z" secondAttribute="top" constant="154" id="tWJ-hf-UuI"/> </constraints> </view> @@ -165,13 +163,67 @@ </objects> <point key="canvasLocation" x="1707.9069767441861" y="3.8626609442060089"/> </scene> + <!--Second View Controller--> + <scene sceneID="q01-MP-XAO"> + <objects> + <viewController storyboardIdentifier="third" id="ULS-Yt-lWP" customClass="SecondViewController" customModule="shop2" customModuleProvider="target" sceneMemberID="viewController"> + <view key="view" contentMode="scaleToFill" id="U8Y-Pl-IYo"> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zkI-2o-vdP"> + <rect key="frame" x="10" y="30" width="300" height="200"/> + <constraints> + <constraint firstAttribute="height" constant="200" id="Wpf-Hb-BJr"/> + </constraints> + </imageView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Uc-MS-K5x"> + <rect key="frame" x="10" y="250.5" width="300" height="19.5"/> + <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="16"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f6g-D8-zVd"> + <rect key="frame" x="10" y="275" width="37.5" height="25"/> + <constraints> + <constraint firstAttribute="height" constant="25" id="OCn-Yz-IiJ"/> + </constraints> + <fontDescription key="fontDescription" type="system" pointSize="15"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + </subviews> + <viewLayoutGuide key="safeArea" id="sqf-fZ-hTP"/> + <color key="backgroundColor" systemColor="systemBackgroundColor"/> + <constraints> + <constraint firstItem="8Uc-MS-K5x" firstAttribute="bottom" secondItem="zkI-2o-vdP" secondAttribute="bottom" constant="40" id="4RM-xf-nPb"/> + <constraint firstItem="sqf-fZ-hTP" firstAttribute="trailing" secondItem="8Uc-MS-K5x" secondAttribute="trailing" constant="10" id="8ae-WG-NOP"/> + <constraint firstItem="8Uc-MS-K5x" firstAttribute="leading" secondItem="sqf-fZ-hTP" secondAttribute="leading" constant="10" id="JCf-Rm-y51"/> + <constraint firstItem="f6g-D8-zVd" firstAttribute="bottom" secondItem="8Uc-MS-K5x" secondAttribute="bottom" constant="30" id="KO6-BM-ifx"/> + <constraint firstItem="f6g-D8-zVd" firstAttribute="leading" secondItem="sqf-fZ-hTP" secondAttribute="leading" constant="10" id="VMR-g2-DJf"/> + <constraint firstItem="sqf-fZ-hTP" firstAttribute="trailing" secondItem="zkI-2o-vdP" secondAttribute="trailing" constant="10" id="bJm-p0-obX"/> + <constraint firstItem="zkI-2o-vdP" firstAttribute="leading" secondItem="sqf-fZ-hTP" secondAttribute="leading" constant="10" id="d70-AK-273"/> + <constraint firstItem="zkI-2o-vdP" firstAttribute="top" secondItem="sqf-fZ-hTP" secondAttribute="top" constant="10" id="jJB-NP-Zgf"/> + <constraint firstItem="f6g-D8-zVd" firstAttribute="leading" secondItem="sqf-fZ-hTP" secondAttribute="leading" constant="10" id="raA-ch-6vi"/> + </constraints> + </view> + <connections> + <outlet property="productImage" destination="zkI-2o-vdP" id="LR0-nt-2e7"/> + <outlet property="productName" destination="8Uc-MS-K5x" id="Obi-K3-SPp"/> + <outlet property="productPrice" destination="f6g-D8-zVd" id="aZ9-bE-Pj4"/> + </connections> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="GRE-ud-G7g" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="1076.25" y="-711.97183098591552"/> + </scene> </scenes> <resources> <systemColor name="systemBackgroundColor"> <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> </systemColor> <systemColor name="systemRedColor"> - <color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> + <color red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> </systemColor> </resources> </document>