Răsfoiți Sursa

Post view included in PostViewController

Iñigo Valentin 9 ani în urmă
părinte
comite
7739360b67
4 a modificat fișierele cu 306 adăugiri și 34 ștergeri
  1. 198 4
      app/Base.lproj/Main.storyboard
  2. 18 13
      app/PostView.swift
  3. 3 4
      app/PostView.xib
  4. 87 13
      app/PostViewController.swift

+ 198 - 4
app/Base.lproj/Main.storyboard

@@ -7,6 +7,7 @@
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
         <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
+        <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -63,7 +64,7 @@
                                 </collectionViewFlowLayout>
                                 <cells>
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="-2.5" width="100" height="50"/>
+                                        <rect key="frame" x="0.0" y="-3" width="100" height="50"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>
@@ -307,13 +308,203 @@
                         <viewControllerLayoutGuide type="top" id="yy6-d2-MRo"/>
                         <viewControllerLayoutGuide type="bottom" id="IxZ-up-5UO"/>
                     </layoutGuides>
-                    <view key="view" contentMode="scaleToFill" id="zcp-qV-FPt" customClass="PostView" customModule="app" customModuleProvider="target">
+                    <view key="view" autoresizesSubviews="NO" contentMode="scaleToFill" id="mCJ-K1-jG1" userLabel="Container">
                         <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                        <color key="backgroundColor" red="0.70980392156862748" green="0.82745098039215681" blue="0.89803921568627454" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                        <subviews>
+                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="arX-Be-0iS" userLabel="Toolbar">
+                                <rect key="frame" x="0.0" y="20" width="320" height="30"/>
+                                <subviews>
+                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="029-px-JqL">
+                                        <rect key="frame" x="0.0" y="0.0" width="48" height="30"/>
+                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
+                                        <state key="normal" title="&lt;">
+                                            <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                        </state>
+                                    </button>
+                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gasteizko Margolariak" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BIE-D1-hCZ">
+                                        <rect key="frame" x="48" y="-0.5" width="224" height="30"/>
+                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
+                                        <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                        <nil key="highlightedColor"/>
+                                    </label>
+                                </subviews>
+                                <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                <constraints>
+                                    <constraint firstItem="BIE-D1-hCZ" firstAttribute="height" secondItem="arX-Be-0iS" secondAttribute="height" id="6Ck-IY-1CK"/>
+                                    <constraint firstItem="029-px-JqL" firstAttribute="centerY" secondItem="arX-Be-0iS" secondAttribute="centerY" id="Es5-Zm-aQk"/>
+                                    <constraint firstItem="BIE-D1-hCZ" firstAttribute="centerY" secondItem="arX-Be-0iS" secondAttribute="centerY" id="PkD-5w-aPZ"/>
+                                    <constraint firstItem="029-px-JqL" firstAttribute="height" secondItem="arX-Be-0iS" secondAttribute="height" id="RTL-TJ-15M"/>
+                                    <constraint firstItem="BIE-D1-hCZ" firstAttribute="width" secondItem="arX-Be-0iS" secondAttribute="width" multiplier="0.7" id="UOQ-6G-qoP"/>
+                                    <constraint firstItem="029-px-JqL" firstAttribute="width" secondItem="arX-Be-0iS" secondAttribute="width" multiplier="0.15" id="VYu-Jc-ahB"/>
+                                    <constraint firstItem="029-px-JqL" firstAttribute="leading" secondItem="arX-Be-0iS" secondAttribute="leading" id="o0K-dB-meB"/>
+                                    <constraint firstItem="BIE-D1-hCZ" firstAttribute="centerX" secondItem="arX-Be-0iS" secondAttribute="centerX" id="zrK-6B-Gff"/>
+                                </constraints>
+                            </view>
+                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jx5-wy-ab4">
+                                <rect key="frame" x="0.0" y="50" width="320" height="518"/>
+                                <subviews>
+                                    <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="14b-YG-Iyb">
+                                        <rect key="frame" x="0.0" y="0.0" width="320" height="518"/>
+                                        <subviews>
+                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yIU-b9-Dc5" userLabel="Section">
+                                                <rect key="frame" x="10" y="10" width="300" height="995"/>
+                                                <subviews>
+                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="Title" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tRk-Ti-VOu" userLabel="Title">
+                                                        <rect key="frame" x="0.0" y="0.0" width="300" height="30"/>
+                                                        <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                        <constraints>
+                                                            <constraint firstAttribute="height" constant="30" id="pTS-D5-LUl"/>
+                                                        </constraints>
+                                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
+                                                        <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                        <nil key="highlightedColor"/>
+                                                    </label>
+                                                    <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="bSp-Sd-3qA" userLabel="Content">
+                                                        <rect key="frame" x="0.0" y="30" width="300" height="965"/>
+                                                        <subviews>
+                                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7t9-eQ-KC7" userLabel="Post">
+                                                                <rect key="frame" x="8" y="8" width="284" height="949"/>
+                                                                <subviews>
+                                                                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="u3M-mi-Tyn" userLabel="Image">
+                                                                        <rect key="frame" x="0.0" y="10" width="284" height="71"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="71" id="fQp-wR-eLU"/>
+                                                                        </constraints>
+                                                                    </imageView>
+                                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2i2-HF-HyI" userLabel="Text">
+                                                                        <rect key="frame" x="14" y="91" width="256" height="826"/>
+                                                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                                        <nil key="textColor"/>
+                                                                        <nil key="highlightedColor"/>
+                                                                    </label>
+                                                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tAc-xa-mg2" userLabel="Separator">
+                                                                        <rect key="frame" x="14" y="917" width="256" height="2"/>
+                                                                        <color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="2" id="TTW-wU-fHT"/>
+                                                                        </constraints>
+                                                                    </view>
+                                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="254" text="Date" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pX4-mq-dj0" userLabel="Date">
+                                                                        <rect key="frame" x="14" y="929" width="256" height="20"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="20" id="Qos-eG-WmY"/>
+                                                                        </constraints>
+                                                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                                        <nil key="textColor"/>
+                                                                        <nil key="highlightedColor"/>
+                                                                    </label>
+                                                                </subviews>
+                                                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                                <constraints>
+                                                                    <constraint firstItem="u3M-mi-Tyn" firstAttribute="width" secondItem="7t9-eQ-KC7" secondAttribute="width" id="4ZF-fF-btB"/>
+                                                                    <constraint firstItem="tAc-xa-mg2" firstAttribute="centerX" secondItem="7t9-eQ-KC7" secondAttribute="centerX" id="Bf4-vV-UnB"/>
+                                                                    <constraint firstItem="pX4-mq-dj0" firstAttribute="width" secondItem="7t9-eQ-KC7" secondAttribute="width" multiplier="0.9" id="Dqr-hS-PV9"/>
+                                                                    <constraint firstItem="2i2-HF-HyI" firstAttribute="centerX" secondItem="7t9-eQ-KC7" secondAttribute="centerX" id="Hoe-4Q-YTi"/>
+                                                                    <constraint firstItem="pX4-mq-dj0" firstAttribute="centerX" secondItem="7t9-eQ-KC7" secondAttribute="centerX" id="U33-D3-0dG"/>
+                                                                    <constraint firstItem="2i2-HF-HyI" firstAttribute="width" secondItem="7t9-eQ-KC7" secondAttribute="width" multiplier="0.9" id="dcP-of-FdV"/>
+                                                                    <constraint firstItem="2i2-HF-HyI" firstAttribute="top" secondItem="u3M-mi-Tyn" secondAttribute="bottom" constant="10" id="enp-lt-dAC"/>
+                                                                    <constraint firstItem="u3M-mi-Tyn" firstAttribute="centerX" secondItem="7t9-eQ-KC7" secondAttribute="centerX" id="gd8-xG-NLo"/>
+                                                                    <constraint firstItem="tAc-xa-mg2" firstAttribute="width" secondItem="7t9-eQ-KC7" secondAttribute="width" multiplier="0.9" id="h9c-Tr-HaL"/>
+                                                                    <constraint firstItem="u3M-mi-Tyn" firstAttribute="top" secondItem="7t9-eQ-KC7" secondAttribute="top" constant="10" id="ilB-HA-43E"/>
+                                                                    <constraint firstAttribute="bottom" secondItem="pX4-mq-dj0" secondAttribute="bottom" id="j3Q-f8-ncG"/>
+                                                                    <constraint firstItem="tAc-xa-mg2" firstAttribute="top" secondItem="2i2-HF-HyI" secondAttribute="bottom" id="sQe-ZF-dDj"/>
+                                                                    <constraint firstItem="pX4-mq-dj0" firstAttribute="top" secondItem="tAc-xa-mg2" secondAttribute="bottom" constant="10" id="y6S-1C-uEC"/>
+                                                                </constraints>
+                                                                <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                                                                <userDefinedRuntimeAttributes>
+                                                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                                                        <color key="value" red="0.42745098040000001" green="0.41176470590000003" blue="0.56470588239999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                    <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                                        <real key="value" value="1"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                    <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                                                        <real key="value" value="3"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                </userDefinedRuntimeAttributes>
+                                                            </view>
+                                                        </subviews>
+                                                        <color key="backgroundColor" red="0.59607843140000005" green="0.7843137255" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                        <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                                                    </stackView>
+                                                </subviews>
+                                                <color key="backgroundColor" red="0.59607843140000005" green="0.7843137255" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                <constraints>
+                                                    <constraint firstItem="bSp-Sd-3qA" firstAttribute="width" secondItem="yIU-b9-Dc5" secondAttribute="width" id="48B-MC-FiI"/>
+                                                    <constraint firstItem="tRk-Ti-VOu" firstAttribute="width" secondItem="yIU-b9-Dc5" secondAttribute="width" id="8hp-PL-zs2"/>
+                                                    <constraint firstAttribute="bottom" secondItem="bSp-Sd-3qA" secondAttribute="bottom" id="AmB-6T-H8u"/>
+                                                    <constraint firstItem="tRk-Ti-VOu" firstAttribute="centerX" secondItem="yIU-b9-Dc5" secondAttribute="centerX" id="GLO-lV-zKm"/>
+                                                    <constraint firstItem="tRk-Ti-VOu" firstAttribute="top" secondItem="yIU-b9-Dc5" secondAttribute="top" id="kvI-es-Bmu"/>
+                                                    <constraint firstItem="bSp-Sd-3qA" firstAttribute="centerX" secondItem="yIU-b9-Dc5" secondAttribute="centerX" id="obg-Sv-CD5"/>
+                                                    <constraint firstItem="bSp-Sd-3qA" firstAttribute="top" secondItem="tRk-Ti-VOu" secondAttribute="bottom" id="wkt-kn-ZPO"/>
+                                                </constraints>
+                                                <edgeInsets key="layoutMargins" top="10" left="10" bottom="10" right="10"/>
+                                                <userDefinedRuntimeAttributes>
+                                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                                        <color key="value" red="0.0" green="0.0" blue="0.066666666669999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                    <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                        <real key="value" value="1"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                    <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                                        <real key="value" value="8"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                </userDefinedRuntimeAttributes>
+                                            </view>
+                                        </subviews>
+                                        <color key="backgroundColor" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        <constraints>
+                                            <constraint firstItem="yIU-b9-Dc5" firstAttribute="top" secondItem="14b-YG-Iyb" secondAttribute="top" constant="10" id="56X-pA-LLg"/>
+                                            <constraint firstItem="yIU-b9-Dc5" firstAttribute="trailing" secondItem="14b-YG-Iyb" secondAttribute="trailing" constant="10" id="8Xl-m3-1Xk"/>
+                                            <constraint firstItem="yIU-b9-Dc5" firstAttribute="centerX" secondItem="14b-YG-Iyb" secondAttribute="centerX" id="8oz-7C-ZSn"/>
+                                            <constraint firstAttribute="bottom" secondItem="yIU-b9-Dc5" secondAttribute="bottom" constant="10" id="BC1-pI-UDI"/>
+                                            <constraint firstItem="yIU-b9-Dc5" firstAttribute="leading" secondItem="14b-YG-Iyb" secondAttribute="leading" constant="10" id="SDQ-gY-p6d"/>
+                                        </constraints>
+                                        <edgeInsets key="layoutMargins" top="10" left="10" bottom="10" right="10"/>
+                                        <userDefinedRuntimeAttributes>
+                                            <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                <real key="value" value="0.0"/>
+                                            </userDefinedRuntimeAttribute>
+                                        </userDefinedRuntimeAttributes>
+                                    </scrollView>
+                                </subviews>
+                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                <constraints>
+                                    <constraint firstItem="14b-YG-Iyb" firstAttribute="top" secondItem="jx5-wy-ab4" secondAttribute="top" id="H0N-Z2-1N1"/>
+                                    <constraint firstItem="14b-YG-Iyb" firstAttribute="width" secondItem="jx5-wy-ab4" secondAttribute="width" id="UPZ-Yz-bgJ"/>
+                                    <constraint firstAttribute="bottom" secondItem="14b-YG-Iyb" secondAttribute="bottom" id="ht1-9m-ecR"/>
+                                    <constraint firstItem="14b-YG-Iyb" firstAttribute="centerX" secondItem="jx5-wy-ab4" secondAttribute="centerX" id="tgi-xm-huK"/>
+                                </constraints>
+                                <userDefinedRuntimeAttributes>
+                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                        <color key="value" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                    </userDefinedRuntimeAttribute>
+                                </userDefinedRuntimeAttributes>
+                            </view>
+                        </subviews>
+                        <color key="backgroundColor" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                        <constraints>
+                            <constraint firstItem="jx5-wy-ab4" firstAttribute="centerX" secondItem="mCJ-K1-jG1" secondAttribute="centerX" id="5lE-sn-JIj"/>
+                            <constraint firstItem="arX-Be-0iS" firstAttribute="top" secondItem="yy6-d2-MRo" secondAttribute="bottom" id="SYd-o2-Nm3"/>
+                            <constraint firstItem="jx5-wy-ab4" firstAttribute="top" secondItem="arX-Be-0iS" secondAttribute="bottom" id="i80-pQ-ZU9"/>
+                            <constraint firstItem="arX-Be-0iS" firstAttribute="centerX" secondItem="mCJ-K1-jG1" secondAttribute="centerX" id="jAL-9l-RFi"/>
+                            <constraint firstItem="jx5-wy-ab4" firstAttribute="width" secondItem="mCJ-K1-jG1" secondAttribute="width" id="lZY-vh-Ap2"/>
+                            <constraint firstItem="arX-Be-0iS" firstAttribute="width" secondItem="mCJ-K1-jG1" secondAttribute="width" id="r1S-WW-h1K"/>
+                            <constraint firstAttribute="bottom" secondItem="jx5-wy-ab4" secondAttribute="bottom" id="xI7-lL-Xhw"/>
+                        </constraints>
+                        <userDefinedRuntimeAttributes>
+                            <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                <real key="value" value="0.0"/>
+                            </userDefinedRuntimeAttribute>
+                        </userDefinedRuntimeAttributes>
                     </view>
                     <connections>
-                        <outlet property="postView" destination="zcp-qV-FPt" id="jXC-Q0-4ao"/>
+                        <outlet property="barButton" destination="029-px-JqL" id="48Y-ht-xLk"/>
+                        <outlet property="barTitle" destination="BIE-D1-hCZ" id="Fwf-72-Zfe"/>
+                        <outlet property="postImage" destination="u3M-mi-Tyn" id="usY-gh-LBn"/>
+                        <outlet property="postText" destination="2i2-HF-HyI" id="Mmz-c2-N6D"/>
+                        <outlet property="postTitle" destination="tRk-Ti-VOu" id="7kU-Dg-MLX"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="r4n-Sk-nt4" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -321,4 +512,7 @@
             <point key="canvasLocation" x="-728" y="1744"/>
         </scene>
     </scenes>
+    <resources>
+        <image name="PhotoPlaceholder" width="170" height="108"/>
+    </resources>
 </document>

+ 18 - 13
app/PostView.swift

@@ -36,14 +36,10 @@ class PostView: UIView {
 	@IBOutlet weak var text: UILabel!
 	
 	@IBOutlet weak var date: UILabel!
-
-	@IBOutlet weak var commentCount: UILabel!
 	
-	@IBOutlet weak var commentList: UIStackView!
-
-	@IBOutlet weak var commentUser: UITextField!
-
-	@IBOutlet weak var commentContent: UITextView!
+	@IBOutlet weak var navigationBar: UINavigationBar!
+	
+	@IBOutlet weak var navigationBarItem: UINavigationItem!
 	
 	// Post id. Must be set pre-segue.
 	var id: Int = -1
@@ -52,9 +48,9 @@ class PostView: UIView {
 		print("POST:LOG: Init (cgrect). Id is \(self.id)")
 		super.init(frame: frame)
 		//Load the contents of the PostView.xib file.
-		Bundle.main.loadNibNamed("PostView", owner: self, options: nil)
-		self.addSubview(container)
-		container.frame = self.bounds
+		//Bundle.main.loadNibNamed("PostView", owner: self, options: nil)
+		//self.addSubview(container)
+		//container.frame = self.bounds
 	}
 	
 	/**
@@ -64,11 +60,20 @@ class PostView: UIView {
 		print("POST:LOG: Init (coder). Id is: \(self.id)")
 		super.init(coder: aDecoder)
 		//Load the contents of the PostView.xib file.
-		Bundle.main.loadNibNamed("PostView", owner: self, options: nil)
-		self.addSubview(container)
-		container.frame = self.bounds
+		//Bundle.main.loadNibNamed("PostView", owner: self, options: nil)
+		//self.addSubview(container)
+		//container.frame = self.bounds
 		
+		//Assign navigation bar items
+		//let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(back))
+		//navigationBarItem.leftBarButtonItem = backButton;
 		
+		
+	}
+	
+	func back() {
+		print("POST:DEBUG: Back")
+		//self.dismiss(animated: true, completion: nil)
 	}
 	
 

+ 3 - 4
app/PostView.xib

@@ -15,6 +15,8 @@
                 <outlet property="container" destination="Zrz-uS-eQa" id="UV8-P9-jMA"/>
                 <outlet property="date" destination="lBQ-aX-qhL" id="esh-vp-DgK"/>
                 <outlet property="image" destination="vwR-EU-h1T" id="ir7-PQ-Awq"/>
+                <outlet property="navigationBar" destination="PAV-4K-mGS" id="N46-pC-GX2"/>
+                <outlet property="navigationBarItem" destination="rxh-zx-B6G" id="PGz-vk-ebK"/>
                 <outlet property="scrollView" destination="8gP-MM-Wzw" id="ZMT-Yf-IoY"/>
                 <outlet property="text" destination="NoQ-Kc-oS7" id="dkU-HT-A7G"/>
                 <outlet property="title" destination="4ub-YM-i5l" id="Sfa-dT-b2M"/>
@@ -36,9 +38,7 @@
                         <color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                     </textAttributes>
                     <items>
-                        <navigationItem title="Gasteizko Margolariak" prompt="&lt;" id="rxh-zx-B6G">
-                            <barButtonItem key="backBarButtonItem" image="Logo" width="10" id="lPX-Uf-eO6"/>
-                        </navigationItem>
+                        <navigationItem title="Gasteizko Margolariak" id="rxh-zx-B6G"/>
                     </items>
                 </navigationBar>
                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ddf-jU-bmv">
@@ -202,7 +202,6 @@
         </view>
     </objects>
     <resources>
-        <image name="Logo" width="83" height="83"/>
         <image name="PhotoPlaceholder" width="170" height="108"/>
     </resources>
 </document>

+ 87 - 13
app/PostViewController.swift

@@ -26,8 +26,13 @@ The view controller of the app.
 */
 class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 	
-	@IBOutlet var postView: PostView!
+
 	
+	@IBOutlet weak var barTitle: UILabel!
+	@IBOutlet weak var barButton: UIButton!
+	@IBOutlet weak var postText: UILabel!
+	@IBOutlet weak var postTitle: UILabel!
+	@IBOutlet weak var postImage: UIImageView!
 	var id: Int = -1
 	var delegate: AppDelegate?
 	
@@ -41,12 +46,6 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 		return NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
 	}
 	
-	func showPost(id: Int){
-		print("POSTCONTROLLER:DEBUG: showPost \(id)")
-		self.postView.id = id
-		self.postView.loadPost(id: id)
-	}
-	
 	/**
 	Run when the app loads.
 	*/
@@ -55,14 +54,11 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 		print("POSTCONTROLLER:LOG: viewDidLoad()")
 		
 		super.viewDidLoad()
-		self.postView.loadPost(id: id)
+		self.loadPost(id: id)
 	}
 	
-	override func viewWillAppear(_ animated: Bool) {
-		let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(back))
-		self.navigationItem.leftBarButtonItem = backButton;
-		super.viewWillAppear(animated);
-	}
+	//TODO implement all the logic for post loading here, including iboutlts
+	
 	
 	func back() {
 		self.dismiss(animated: true, completion: nil)
@@ -76,5 +72,83 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 		super.didReceiveMemoryWarning()
 	}
 	
+	public func loadPost(id: Int){
+		
+		print("POSTCONTROLLER:DEBUG: Loading post \(id)")
+		
+		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+		let appDelegate = UIApplication.shared.delegate as! AppDelegate
+		let lang : String = getLanguage()
+		context.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
+		let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest()
+		fetchRequest.predicate = NSPredicate(format: "id = %i", id)
+		
+		do {
+			//go get the results
+			let searchResults = try context.fetch(fetchRequest)
+			
+			var count = 0
+			var sTitle: String
+			var sText: String
+			var image: String
+			
+			//You need to convert to NSManagedObject to use 'for' loops
+			for r in searchResults as [NSManagedObject] {
+				count = count + 1
+				
+				sTitle = r.value(forKey: "title_\(lang)")! as! String
+				sText = r.value(forKey: "text_\(lang)")! as! String
+				postTitle.text = "  \(sTitle)"
+				postText.text = sText.stripHtml()
+				
+				// Get main image
+				image = ""
+				let imgFetchRequest: NSFetchRequest<Post_image> = Post_image.fetchRequest()
+				let imgSortDescriptor = NSSortDescriptor(key: "idx", ascending: true)
+				let imgSortDescriptors = [imgSortDescriptor]
+				imgFetchRequest.sortDescriptors = imgSortDescriptors
+				imgFetchRequest.predicate = NSPredicate(format: "post == %i", id)
+				imgFetchRequest.fetchLimit = 1
+				//TODO get more images
+				do{
+					let imgSearchResults = try context.fetch(imgFetchRequest)
+					for imgR in imgSearchResults as [NSManagedObject]{
+						image = imgR.value(forKey: "image")! as! String
+						print ("POST:LOG: Image: \(image)")
+						//TODO set image
+						//row.setImage(filename: image)
+					}
+				} catch {
+					print("POST:ERROR: Error getting image for post \(id): \(error)")
+				}
+				
+			}
+		} catch {
+			print("POST:ERROR: Error with request: \(error)")
+		}
+		
+		//Always at the end: update scrollview
+		// TODOs
+		//var h: Int = 0
+		//for view in scrollView.subviews {
+			//contentRect = contentRect.union(view.frame);
+		//	h = h + Int(view.frame.height) + 30 //Why 30?
+		//}
+		//print("POST:DEBUG: Height: \(h)")
+		// TODO: Calculate at the end
+		//self.scrollView.contentSize.height = 4500//CGFloat(h);
+
+	}
+	
+	func getLanguage() -> String{
+		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
+		if(pre == "es" || pre == "en" || pre == "eu"){
+			return pre
+		}
+		else{
+			return "es"
+		}
+	}
+	
 }