【发布时间】:2015-10-02 18:15:11
【问题描述】:
我目前正在制作一个用于快速练习的演示 iOS 应用程序,但遇到了一个问题。我刚刚创建了一个新页面,这个页面上只有一个按钮。我已将该按钮链接到 IBAction 函数,它显示了正确的连接。
我会给你看一个屏幕截图,但我没有足够的声誉(我遇到的所有其他问题我都可以找到其他人的帖子)。
它甚至会显示带有实心圆点的圆圈,并且在单击时会显示正确的按钮。在连接检查器中,它在发送的事件下显示了“Touch Up Inside”和“UserPage btnProgressClick”之间的连接(Userpage 是我的类,它扩展了 UIViewController 并被这个特定的 View Controller 引用,btnProgressClick 是我想要的 IBAction 函数的名称运行)。
我找到了this post,我尝试了一个干净的构建,但没有奏效。我还移动了我的按钮并在模拟器中正确更新。
btnProgressClick 中的代码永远不会执行。我在第一行放了一个断点,它没有中断。
这是将按钮链接到函数的“Main.storyboard”XML 代码。
<!--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>
这里是 UserPage 类:
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)
}
}
正如我之前所说,这是我的第一个问题,因此我愿意就其措辞方式和我提供的信息提供反馈。
我想添加一些有关如何调用此页面的信息。它在对 Web 服务的异步调用之后调用。成功取回数据后,我使用此功能转换到页面:
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)
}
}
不确定这是否会有所不同,但我想我会把它扔在那里。
关于这个问题的任何帮助都会非常有用。
谢谢!!
【问题讨论】:
-
您如何验证该函数没有被调用,您是否尝试在该函数中放置一个断点以验证它没有发生?
-
同意。听起来插座是正确制作的,所以我很好奇是否正在调用任何函数。
-
是的,这正是我所做的。断点从未被击中。对不起,我应该把它放在帖子里。
-
@IBAction应该这样做,但尝试将关键字dynamic放在@IBAction和func之间。 -
只是想评论一下您在第一个问题上做得很好。感谢您付出努力并展示您迄今为止所做的尝试。