Procházet zdrojové kódy

Can't load post from ViewController.

Iñigo Valentin před 9 roky
rodič
revize
2e991976c6
4 změnil soubory, kde provedl 66 přidání a 19 odebrání
  1. 1 1
      app/Base.lproj/Main.storyboard
  2. 28 15
      app/PostView.swift
  3. 11 1
      app/PostView.xib
  4. 26 2
      app/ViewController.swift

+ 1 - 1
app/Base.lproj/Main.storyboard

@@ -317,7 +317,7 @@
                         <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">
+                    <view key="view" contentMode="scaleToFill" id="zcp-qV-FPt" customClass="PostView" customModule="app" customModuleProvider="target">
                         <rect key="frame" x="0.0" y="0.0" width="320" height="458"/>
                         <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"/>

+ 28 - 15
app/PostView.swift

@@ -29,28 +29,32 @@ class PostView: UIView {
 	//The main scroll view.
 	@IBOutlet weak var scrollView: UIScrollView!
 
-	
 	@IBOutlet weak var title: UILabel!
-	
+
 	@IBOutlet weak var image: UIImageView!
 	
 	@IBOutlet weak var text: UILabel!
-	
+
 	@IBOutlet weak var imageExtra: UIStackView!
 	
 	@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!
 	
 	
 	override init(frame: CGRect){
+		print("POST:DEBUG: Init cgrect")
 		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
 	}
 	
 	/**
@@ -58,7 +62,7 @@ class PostView: UIView {
 	*/
 	required init?(coder aDecoder: NSCoder) {
 		
-		print("POST:DEBUG: Init")
+		print("POST:DEBUG: Init coder")
 		
 		super.init(coder: aDecoder)
 		
@@ -70,19 +74,27 @@ class PostView: UIView {
 		
 	}
 	
-	func loadPost(id : Int){
+	open func lp(){
+		print("POST:DEBUG: Lp");
+	}
+	
+	public func loadPost(id: Int) -> Bool{
 	
-		// Show post
+		print("POST:DEBUG: Loading post \(id)")
+		
+		// TODO Show post
 		/*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)
+		fetchRequest.predicate = NSPredicate(format: "post = %i", id)
+		
+		//title.text = "AAAAA"
 		
 		do {
 			//go get the results
-			let searchResults = try context.fetch(fetchRequest)
+			/*let searchResults = try context.fetch(fetchRequest)
 			
 			//I like to check the size of the returned results!
 			print ("Post: \(searchResults.count)")
@@ -125,20 +137,21 @@ class PostView: UIView {
 					print("Error getting image for post \(id): \(error)")
 				}
 				
-			}
+			}*/
 		} catch {
 			print("Error with request: \(error)")
 		}
 		
 		//Always at the end: update scrollview
-		var h: Int = 0
+		/*var h: Int = 0
 		for view in scrollView.subviews {
 			//contentRect = contentRect.union(view.frame);
 			h = h + Int(view.frame.height) + 30 //Why 30?
-			print("Blog curh: \(h)")
 		}
 		// TODO: Calculate at the end
-		self.scrollView.contentSize.height = 2500//CGFloat(h);*/
+		self.scrollView.contentSize.height = 2500//CGFloat(h);*/*/
+		
+		return true
 	}
 	
 	func getLanguage() -> String{

+ 11 - 1
app/PostView.xib

@@ -9,9 +9,19 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PostView" customModule="app" customModuleProvider="target">
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PostView" customModule="app">
             <connections>
+                <outlet property="commentContent" destination="kba-hh-hSu" id="9GT-ve-VVs"/>
+                <outlet property="commentCount" destination="w3V-dl-ijf" id="hGh-d8-JEX"/>
+                <outlet property="commentList" destination="For-Ru-u5Y" id="TgM-Zb-zEy"/>
+                <outlet property="commentUser" destination="4Rd-hH-5iP" id="5ri-0c-cz4"/>
                 <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="imageExtra" destination="L5f-5R-97B" id="cUG-OH-etX"/>
+                <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"/>
             </connections>
         </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>

+ 26 - 2
app/ViewController.swift

@@ -38,7 +38,9 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	@IBOutlet weak var containerViewLablanca: UIView!
 	@IBOutlet weak var containerViewLocation: UIView!
 	@IBOutlet weak var containerViewHome: HomeView!
-	@IBOutlet weak var containerViewPost: PostView!
+	@IBOutlet var containerViewPost: PostView!
+	
+	var refViewPost: PostView!
 	
 	
 	func getContext () -> NSManagedObjectContext {
@@ -49,6 +51,11 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	
 	func showPost(id: Int){
 		print("CONTROLLER:DEBUG: showPost \(id)")
+		
+		if self.containerViewPost == nil{
+			print("CONTROLLER:DEBUG: containerViewPost has been released")
+		}
+		
 		UIView.animate(withDuration: 0.5, animations: {
 			self.containerViewHome.alpha = 0
 			self.containerViewLocation.alpha = 0
@@ -58,6 +65,13 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 			self.containerViewGallery.alpha = 0
 			self.containerViewPost.alpha = 1
 		})
+		
+		
+		//TODO get the uiview from the storyboard again
+		//self.storyboard?..instantiateViewController(withIdentifier: "PostView")
+		self.containerViewPost = PostView()
+		containerViewPost.title.text = "AAAAA"
+		//hself.refViewPost.loadPost(id: id)
 	}
 	
 	/**
@@ -71,7 +85,11 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		self.containerViewActivities.alpha = 0
 		self.containerViewBlog.alpha = 0
 		self.containerViewGallery.alpha = 0
-		self.containerViewPost.alpha = 0
+		self.containerViewPost.alpha = 0.2
+		
+		self.refViewPost = self.containerViewPost
+		
+		
 		
 		//self.containerViewBlog.isHidden = true
 				
@@ -86,6 +104,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		
 		delegate = UIApplication.shared.delegate as! AppDelegate
 		delegate?.controller = self
+		
+		
+		//self.containerViewPost.loadPost(id: 16)
+		print(type(of:containerViewPost))
+		5//self.containerViewPost.lp()
+		print(self.containerViewBlog.borderColor)
 	}
 
 	/**