当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Changing button label in the container view by clicking button in the main view

问题描述:

I'm new to IOS programming. In my app, I have a container view which is connected to a page view controller with three pages. It works well. When I push a button in the main view controller, I want to change the button labels in the container view. So, I must connect a variable in the main view to a variable in the page view controller. I write like the below, but it crashes when I clicked the button (SIGABRT signal)..

@IBAction func pressShift(sender: AnyObject) {

if (self.shift != 3) {

self.shift++

}

else {

self.shift = 1

}

performSegueWithIdentifier("container", sender: sender)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

var scene = segue.destinationViewController as! FeaturesViewController

scene.shiftNumber = self.shift

}

I made a simple example project. A container view in the main view. There is a label in the container view (not page view controller) and a button in the main view. I wrote the same code, but again the same error occurs.

Here is the image of my storyboard...

Storyboard Image

Example project: http://www.filedropper.com/exampletosegue

网友答案:

I solved the problem by removing the child view which has already created at the first start..

@IBAction func insertButton(sender: AnyObject) {

    if (shiftNo != 3) {
        shiftNo++
    }
    else {
        shiftNo = 1
    }

    var childView = self.childViewControllers[0] as! UIViewController
    childView.willMoveToParentViewController(nil)
    childView.view.removeFromSuperview()
    childView.removeFromParentViewController()

    performSegueWithIdentifier("container", sender: self)
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: