Jelajahi Sumber

Access to the controller from BlogView

Iñigo Valentin 9 tahun lalu
induk
melakukan
4a168ccb68
3 mengubah file dengan 16 tambahan dan 4 penghapusan
  1. 1 0
      app/AppDelegate.swift
  2. 2 2
      app/Base.lproj/Main.storyboard
  3. 13 2
      app/BlogView.swift

+ 1 - 0
app/AppDelegate.swift

@@ -122,5 +122,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 			}
 		}
 	}
+	
 }
 

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

@@ -23,10 +23,10 @@
                 <placeholder placeholderIdentifier="IBFirstResponder" id="utt-1m-pei" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
         </scene>
-        <!--Gasteizko Margolariak-->
+        <!--GMViewController-->
         <scene sceneID="tne-QT-ifu">
             <objects>
-                <viewController title="Gasteizko Margolariak" id="BYZ-38-t0r" customClass="ViewController" customModule="app" customModuleProvider="target" sceneMemberID="viewController">
+                <viewController storyboardIdentifier="GMViewController" title="Gasteizko Margolariak" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BYZ-38-t0r" userLabel="GMViewController" customClass="ViewController" customModule="app" customModuleProvider="target" sceneMemberID="viewController">
                     <layoutGuides>
                         <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
                         <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>

+ 13 - 2
app/BlogView.swift

@@ -37,8 +37,9 @@ class BlogView: UIView {
 	//Each of the sections of the view.
 	@IBOutlet weak var section: Section!
 	
-	var controller : ViewController? = nil
+	//var controller : ViewController
 	
+	var delegate: AppDelegate? = nil
 	
 	override init(frame: CGRect){
 		super.init(frame: frame)
@@ -60,9 +61,14 @@ class BlogView: UIView {
 		section.setTitle(text: "Blog")
 		let parent = section.getContentStack()
 		
+		// Get viewController from StoryBoard
+		let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
+		let controller = storyboard.instantiateViewController(withIdentifier: "GMViewController") as! ViewController
+		
 		// Show posts
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
+		self.delegate = appDelegate
 		let lang : String = getLanguage()
 		context.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest()
@@ -115,7 +121,7 @@ class BlogView: UIView {
 						row.setImage(filename: image)
 					}
 				} catch {
-					print("Error getting image for post \(id): \(error)")
+					print("BLOG:ERROR: Error getting image for post \(id): \(error)")
 				}
 				
 				print("BLOG:DEBUG: Row height: \(row.frame.height)")
@@ -151,6 +157,11 @@ class BlogView: UIView {
 		
 		//viewController.showPost(id: 4)
 		
+		print("BLOG:DEBUG: Show post on load.")
+		//self.delegate?.controller?.showPost(id: 4)
+		
+		controller.showPost(id: 4)
+