IBAction func is connected correctly but does not execute

I am currently making a demo application for iOS for quick work, and I ran into a problem. I just created a new page and there is only one button on this page. I associated the button with the IBAction function and showed the correct connection.

I would show you a screenshot, but I don't have enough reputation (every other question I ever had, I could find a message from someone else).

It even shows a circle with a filled dot, and when you click on it, the correct button is displayed. In the connection inspector, it displays, when the events are sent, the connection between "Touch Up Inside" and "UserPage btnProgressClick" (Userpage is my class that extends the UIViewController and refers to this batch view controller, and btnProgressClick is the name of the IBAction function that I want to work )

I found this post and I tried a clean build, but that didn't work. I also moved my button around and it updated correctly in the simulator.

The code inside btnProgressClick is never executed. I set a breakpoint in the first line and did not break.

Here is the XML code "Main.storyboard" that associates a button with a function.

    <!--User Page-->
    <scene sceneID="aNb-aX-hZF">
        <objects>
            <viewController storyboardIdentifier="UserPage" id="w2h-zR-Kdu" customClass="UserPage" customModule="GenomeTrackerDemo" customModuleProvider="target" sceneMemberID="viewController">
                <layoutGuides>
                    <viewControllerLayoutGuide type="top" id="9dS-Hw-ZYg"/>
                    <viewControllerLayoutGuide type="bottom" id="7PS-pA-lFe"/>
                </layoutGuides>
                <view key="view" contentMode="scaleToFill" id="w6A-eT-aKv">
                    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <subviews>
                        <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JGD-xx-tMQ">
                            <rect key="frame" x="20" y="48" width="46" height="30"/>
                            <state key="normal" title="Button"/>
                            <connections>
                                <action selector="btnProgressClick:" destination="w2h-zR-Kdu" eventType="touchUpInside" id="F1N-QY-fhb"/>
                            </connections>
                        </button>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                </view>
            </viewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="Fsq-L4-Are" userLabel="First Responder" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="1043" y="426"/>
    </scene>

and here is the UserPage class:

import Foundation
import UIKit

class UserPage: UIViewController {

    var thisUser: User = User()

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func btnProgressClick(sender: UIButton) {

        let storyboard = UIStoryboard(name: "Main", bundle:nil)

        let vc: progressPage = storyboard.instantiateViewControllerWithIdentifier("progressPage") as! progressPage


        UIView.transitionFromView(self.view, toView: vc.view, duration: 0.8, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
    }

}

, , , .

, . Async -. , , :

func afterSuccessfulLogin(thisUser: User){

    dispatch_async(dispatch_get_main_queue()){
        let storyboard = UIStoryboard(name: "Main", bundle:nil)

        let vc: UserPage = storyboard.instantiateViewControllerWithIdentifier("UserPage") as! UserPage
        vc.thisUser = thisUser


        UIView.setAnimationCurve(.EaseIn)

        UIView.transitionFromView(self.view, toView: vc.view, duration: 1.2, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
    }
} 

, , , .

.

!!

+4
1

[ , - , )

iOS . . , , . :

  • addChildViewController: on self transitionFromView:toView:duration:options:completion: vc.
  • transitionFromView:toView:duration:options:completion: didMoveToParentViewController: on vc, self.

    let storyboard = UIStoryboard(name: "Main", bundle:nil)
    
    let vc: UserPage = storyboard.instantiateViewControllerWithIdentifier("UserPage") as! UserPage
    vc.thisUser = thisUser
    
    
    UIView.setAnimationCurve(.EaseIn)
    
    self.addChildViewController(vc)
    UIView.transitionFromView(self.view, toView: vc.view, duration: 1.2, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: { (finished) -> Void in vc.didMoveToParentViewController(self) })
    

transitionFromView:toView:duration:options:completion: self.view fromView. fromView toView, . , UIView, self.view.

+1

Source: https://habr.com/ru/post/1610018/


All Articles