下一个VC没有显示

时间:2016-09-07 02:13:18

标签: ios swift

我有一个segue从第一个VC clubSelectionViewController到下面显示的clubSummaryViewController,但我必须单击两次才能显示下一个VC。我做错了什么?

import Foundation
import UIKit

class clubSelectionViewController: UIViewController, UITableViewDelegate {
    var clubsForSelection = [clubObject]()
    var clubForClubSummaryView = [clubObject]()

    @IBAction func selectDanceClubs(sender: AnyObject) {
        clubForClubSummaryView = clubDataFilter.removeStripClubsFrom(clubsForSelection)

        self.performSegueWithIdentifier("ClubSummary", sender: self)
    }

    @IBAction func selectStripClubs(sender: AnyObject) {
        clubForClubSummaryView = clubDataFilter.removeDanceClubsFrom(clubsForSelection)

        self.performSegueWithIdentifier("ClubSummary", sender: self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // everytime screen loads it removes information to give blank screen it removes all clubs in array
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "ClubSummary" {
            let summaryView = segue.destinationViewController as! clubSummaryViewController
            summaryView.clubDetails = [clubObject]()
            summaryView.clubDetails = self.clubForClubSummaryView
        }
    }
}

第二个VC

import UIKit

class clubSummaryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var clubDetails = [clubObject]()
    var selectedClub = clubObject()

    @IBOutlet var clubSummaryTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        //Declare Delegate, Load TableView
        clubSummaryTableView.delegate = self
        //clubSummaryTableView.dataSource = self
        clubSummaryTableView.reloadData()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: TableViewDelegate

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         return self.clubDetails.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell =  self.clubSummaryTableView.dequeueReusableCellWithIdentifier("SummaryCell")! as? clubSummaryCell

        cell?.clubName.text = clubDetails[indexPath.row].clubName
        cell?.clubAddress.text = clubDetails[indexPath.row].clubAddress

        //TODO: insert image
        cell?.clubPhoto.image = clubDetails[indexPath.row].clubImage.image

        return cell!
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.selectedClub = self.clubDetails[indexPath.row]

        self.performSegueWithIdentifier("ClubDetails", sender: self)
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "ClubDetails"{
            let clubDetailsView = segue.destinationViewController as? clubInfoViewController
            clubDetailsView?.clubForDetails = self.selectedClub     
        }
    }
}

2 个答案:

答案 0 :(得分:0)

我认为问题在于:

@IBAction func selectDanceClubs(sender: AnyObject) {
    clubForClubSummaryView = clubDataFilter.removeStripClubsFrom(clubsForSelection)

    self.performSegueWithIdentifier("ClubSummary", sender: self)
}

@IBAction func selectStripClubs(sender: AnyObject) {
    clubForClubSummaryView = clubDataFilter.removeDanceClubsFrom(clubsForSelection)

    self.performSegueWithIdentifier("ClubSummary", sender: self)
}

我不确定你为什么要这两个func具有相同的SegueWithIdentifier

答案 1 :(得分:0)

原因可能是你已经从按钮本身附加了segue。

这意味着当你点击按钮时,按钮的segue被调用,并且由于你也有按钮的动作,所以从动作方法再次调用segue。

意思是,同一个segue被调用两次。