使用navigationController PushViewController时的Exc_Bad_Instruction

时间:2015-01-02 19:10:27

标签: ios swift pushviewcontroller navigationcontroller

我试图在用户选择表格单元格时推送到不同的视图,当我到达推送的位置时,它会抛出错误。

这里的特殊情况是我在同一个UIViewController下使用tableViews工作两个UIViews。因此,UIView和TableDelegates属于他们自己的类。

非常感谢任何建议。

import Foundation
import UIKit
import CoreData

class FavoritesViewController: UIViewController {

//MARK: - UIViewController Delegates
override func viewWillAppear(animated: Bool) {}
}


//MARK: - Lenders Table View Delegates
class FavoritesLenderViewController:  UIView, UITableViewDelegate, UITableViewDataSource {

let favoritesViewController = FavoritesViewController()
let lenderDetailsViewController = LenderDetailsViewController()

var lenders = Array<Lenders>()
var lenderUserComments = Array<LenderUserComments>()
let lendersModel = LendersModel()

//MARK:  View Parameters
@IBOutlet weak var favoriteLendersTableView: UITableView!

// Equivalent to viewWillAppear for a subclass.
override func willMoveToSuperview(newSuperview: UIView?) {
    self.lenders = lendersModel.readLenderData() as Array

    // Reload data (for when the user comes back to this page from the details page.)
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.favoriteLendersTableView.reloadData()
    })
}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var favoritesViewController = FavoritesViewController()
    return self.lenders.count
}



// On selecting, send variables to target class.
func tableView(tableView: UITableView!, didSelectRowAtIndexPath path: NSIndexPath!) {

    // Setup what segue path is going to be used on selecting the row as set the type as the class for the view your going to.
    let lenderDetailsViewController = self.favoritesViewController.storyboard?.instantiateViewControllerWithIdentifier("LendersDetailsView") as LenderDetailsViewController

    // Get the lenderId from the selected path.row and put the values to the variables in the target class.
    let lendersNSArray = lenders as NSArray
    lenderDetailsViewController.lenderIdPassed = lendersNSArray[path.row].valueForKey("lenderId") as String!

    //  tell the new controller to present itself
// BREAKS HERE : EXC_BAD_INSTRUCTION code=EXC_I386_INVOP
    lenderDetailsViewController.navigationController?.pushViewController(lenderDetailsViewController, animated: true)

}

....//additional table delegates
}

1 个答案:

答案 0 :(得分:0)

你不要自己推动新的视图控制器。试试这个:

self.navigationController?.pushViewController(lenderDetailsViewController, animated: true)