【问题标题】:How can I call an action through UIButton variable如何通过 UIButton 变量调用操作
【发布时间】:2016-05-10 13:13:25
【问题描述】:

我有一个UIButton 原型UItableviewcell,它是用笔尖制作的。 UITableView 位于 UIViewController 内。 要求是:当我按下UIButton 时,应该从Main UIViewController 到另一秒UIViewController 执行segue。我可以从 table 访问 UIButton IBOutlet ,所以有什么方法可以通过该 UIButton 变量调用函数。 // for reference let x= cell.followButton;

【问题讨论】:

标签: ios iphone swift uitableview uibutton


【解决方案1】:

向按钮添加目标以调用视图控制器中的方法。在这段代码中,self 是您的视图控制器。

cell.followButton.addTarget(self, action: #selector(buttonPressed), forControlEvents: .TouchUpInside)

然后实现buttonPressed 来处理segueing。

func buttonPressed() {
    performSegueWithIdentifier("Identifier", sender: self)
}

【讨论】:

    猜你喜欢
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多