无法将字符串转换为日期应用程序崩溃并显示插座为零

时间:2017-06-04 17:44:58

标签: ios swift

我正在从笔尖加载视图并且我已成功加载但是第一个加载完美但在第二个视图中获取零个出口。下面是我的代码。

默认情况下,将一个全局变量设置为loadview为0,当我按下一个按钮时,它会增加。

用户是这里的结构:

path: '', // right
component: CalendarComponent,
...

此方法位于我的ViewController

struct User {
static var quizIndexNo      =   0
}

从此数组中获取视图名称:     让viewName = [“MOPT”,“RMK”]

let moptViewInstance    =   MOPT()
let rmkViewInstance     =   RMK()

// NIB查看类

func loadQuizView(){

        if viewName[User.quizIndexNo] == "MOPT" {

            for views in vwOptionView.subviews {
                views.removeFromSuperview()
            }

            moptViewInstance.prepareScreenWithView(navigationController: UINavigationController(), viewSize: self.vwOptionView, viewController: self)

        } else if viewName[User.quizIndexNo] == "RMK" {

            for views in vwOptionView.subviews {
                views.removeFromSuperview()
            }
            rmkViewInstance.prepareScreenWithView(navigationController: UINavigationController(), viewSize: self.vwOptionView, viewController: self)

        }
}

第二个NibView类     RMK类:UIView {

class MOPT: UIView {

@IBOutlet weak var btnPrevious: UIButton!
@IBOutlet weak var btnNext: UIButton!

var nibView: UIView!
var instanceOfQuizController : QuizCointroller!

func prepareScreenWithView(navigationController: UINavigationController, viewSize: UIView, viewController: UIViewController) {

    nibView = Bundle.main.loadNibNamed("MOPT", owner: self, options: nil)?[0] as! UIView
    nibView.tag = 200
    var tempRect = nibView.frame
    print(tempRect)

    if User.quizIndexNo == 0 {
        btnPrevious.isHidden = true
    }

    if User.quizIndexNo == 0 {
        btnNext.setTitle("Test", for: .normal)
    }

    print("Index No is: \(User.quizIndexNo) and \(Sequence.totalQuizQuestionCout)")

    if User.quizIndexNo == Sequence.totalQuizQuestionCout - 1 {
        btnNext.setTitle("Submit", for: .normal)
    }

    instanceOfQuizController = viewController as! QuizCointroller

    tempRect =  CGRect(x: 0, y: 0, width: viewSize.bounds.width, height: viewSize.bounds.height)
    viewSize.addSubview(self.nibView)
    self.nibView.frame = tempRect

}

@IBAction func btnPrev(_ sender: UIButton) {
    User.quizIndexNo -= 1
    Sequence.instanceOfQuizControllerTest.previousButtonPressed()

}
// Next button will reload next view 
@IBAction func btnNext(_ sender: UIButton) {
    User.quizIndexNo += 1
   // here sequence is global variable of type ViewController
    Sequence.instanceOfQuizControllerTest.nextButtonPressed()


    }
}

0 个答案:

没有答案