Iñigo Valentin 9 лет назад
Родитель
Сommit
00dfd91ed3
4 измененных файлов с 21 добавлено и 28 удалено
  1. 3 0
      app/Base.lproj/Main.storyboard
  2. 12 26
      app/PostView.swift
  3. 1 1
      app/PostView.xib
  4. 5 1
      app/PostViewController.swift

+ 3 - 0
app/Base.lproj/Main.storyboard

@@ -312,6 +312,9 @@
                         <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"/>
                     </view>
+                    <connections>
+                        <outlet property="postView" destination="zcp-qV-FPt" id="jXC-Q0-4ao"/>
+                    </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="r4n-Sk-nt4" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>

+ 12 - 26
app/PostView.swift

@@ -47,10 +47,11 @@ class PostView: UIView {
 
 	@IBOutlet weak var commentContent: UITextView!
 	
+	// Post id. Must be set pre-segue.
 	var id: Int = -1
 	
 	override init(frame: CGRect){
-		print("POST:DEBUG: Init cgrect")
+		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)
@@ -62,11 +63,8 @@ class PostView: UIView {
 	Run when the view is started.
 	*/
 	required init?(coder aDecoder: NSCoder) {
-		
-		print("POST:DEBUG: Init coder")
-		
+		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)
@@ -75,30 +73,20 @@ class PostView: UIView {
 		
 	}
 	
-	open func lp(){
-		print("POST:DEBUG: Lp");
-	}
-	
 	public func loadPost(id: Int) -> Bool{
 	
 		print("POST:DEBUG: Loading post \(id)")
 		
-		// TODO Show post
-		/*let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+		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: "post = %i", id)
-		
-		//title.text = "AAAAA"
+		fetchRequest.predicate = NSPredicate(format: "id = %i", id)
 		
 		do {
 			//go get the results
-			/*let searchResults = try context.fetch(fetchRequest)
-			
-			//I like to check the size of the returned results!
-			print ("Post: \(searchResults.count)")
+			let searchResults = try context.fetch(fetchRequest)
 			
 			var count = 0
 			var sTitle: String
@@ -108,9 +96,6 @@ class PostView: UIView {
 			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
-				//get the Key Value pairs (although there may be a better way to do that...
-				print("Perm: \(r.value(forKey: "permalink"))")
-				
 				
 				sTitle = r.value(forKey: "title_\(lang)")! as! String
 				sText = r.value(forKey: "text_\(lang)")! as! String
@@ -130,27 +115,28 @@ class PostView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
-						print ("IMAGE: \(image)")
+						print ("POST:LOG: Image: \(image)")
 						//TODO set image
 						//row.setImage(filename: image)
 					}
 				} catch {
-					print("Error getting image for post \(id): \(error)")
+					print("POST:ERROR: Error getting image for post \(id): \(error)")
 				}
 				
-			}*/
+			}
 		} catch {
-			print("Error with request: \(error)")
+			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?
 		}
 		// TODO: Calculate at the end
-		self.scrollView.contentSize.height = 2500//CGFloat(h);*/*/
+		self.scrollView.contentSize.height = 2500//CGFloat(h);*/
 		
 		return true
 	}

+ 1 - 1
app/PostView.xib

@@ -76,7 +76,7 @@
                                                                 <constraint firstAttribute="height" constant="128" id="rXJ-QA-Rv2"/>
                                                             </constraints>
                                                         </imageView>
-                                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NoQ-Kc-oS7" userLabel="Text">
+                                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NoQ-Kc-oS7" userLabel="Text">
                                                             <rect key="frame" x="8" y="142" width="268" height="20.5"/>
                                                             <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                             <nil key="textColor"/>

+ 5 - 1
app/PostViewController.swift

@@ -26,6 +26,8 @@ The view controller of the app.
 */
 class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 	
+	@IBOutlet var postView: PostView!
+	
 	var id: Int = -1
 	var delegate: AppDelegate?
 	
@@ -41,6 +43,8 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 	
 	func showPost(id: Int){
 		print("POSTCONTROLLER:DEBUG: showPost \(id)")
+		self.postView.id = id
+		self.postView.loadPost(id: id)
 	}
 	
 	/**
@@ -51,7 +55,7 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
 		print("POSTCONTROLLER:LOG: viewDidLoad()")
 		
 		super.viewDidLoad()
-		
+		self.postView.loadPost(id: id)
 	}
 	
 	/**