mercredi 24 juin 2015

Swift - Table View Black Screen?

I'm trying to present the TableViewController after the user is done sharing with the ActivityViewController. Here's my method for that :

 @IBAction func share(sender: UIBarButtonItem) {
        var   memeedimage = generateMemedImage()

        let activityViewController = UIActivityViewController(activityItems:[memeedimage] , applicationActivities: nil)
        presentViewController(activityViewController, animated: true, completion: nil)

        activityViewController.completionWithItemsHandler = {
            (activity, success, returneditems, error) in
            println("Activity: \(activity) Success: \(success) Items: \(returneditems) Error: \(error)")
            self.save()
            activityViewController.dismissViewControllerAnimated(true, completion: nil)


            let memevc:MemeTableViewController  = MemeTableViewController()
            self.presentViewController(memevc, animated: true, completion: nil)
        }

I already dismissed the activityviewcontroller and the self.presentviewcontroller is referring to the viewthatcontroller that presented the activityViewController . However, I just get a black screen once the user is done sharing.

Why is this? I believe it's because my tableview did not load properly.

Here's my MemeTableViewController code :

import UIKit

class MemeTableViewController : UIViewController,UITableViewDelegate,UITableViewDataSource
{
    var memesz: [MemeObject]!

    @IBOutlet var tableView: UITableView!

    override func viewWillAppear(animated: Bool) {            
            super.viewWillAppear(animated)
            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            memesz = appDelegate.memes
            //tableView.reloadData()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.hidesBarsOnSwipe = true
        navigationController?.hidesBarsOnTap = true            
    }

    //reserves the number of rows needed to display the image
       func tableView(tableView : UITableView, numberOfRowsInSection section : Int)->Int
       {
            println("ARE YOU SERIOUS")
            return memesz.count
        }

    //Reserves the row to be dequeued for display
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {            
        let cell:TableViewzCell = tableView.dequeueReusableCellWithIdentifier("MemesCell", forIndexPath: indexPath) as! TableViewzCell
        let memezrow =  memesz[indexPath.row]
        cell.label1.text = memezrow.textFieldtop
        cell.label2.text = memezrow.textFieldbottom
        cell.imageview.image = memezrow.memedImage
        println("Why is this not being called")

            return cell
    }

    //Method to do something when the row is selected
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let detailController = self.storyboard!.instantiateViewControllerWithIdentifier("FullScreenMeme") as! FullScreenMeme
        detailController.meme = memesz[indexPath.row]
        self.navigationController!.pushViewController(detailController, animated: true)
        println("This too")
    }
}

See more ..

Aucun commentaire:

Enregistrer un commentaire