【发布时间】:2015-10-04 04:44:04
【问题描述】:
我使用以下代码在 Swift 中以编程方式创建了一个按钮:
let image = UIImage(named: "pin") as UIImage?
let button = UIButton();
button.setTitle("Add", forState: .Normal)
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
button.setImage(image, forState: .Normal)
button.frame = CGRectMake(15, -50, 200, 38)
button.center = CGPointMake(190.0, 345.0);// for center
self.view.addSubview(button)
我有一个单独的函数来尝试使用带有标识符 segueOnPin 的 segue:
@IBAction func segueToCreate(sender: UIButton) {
// do something
performSegueWithIdentifier("segueOnPin", sender: nil)
}
但是,我认为新的 UIbutton 没有正确连接到第二个功能,因为它不起作用。我通常将它连接到 StoryBoard 上。但是,新按钮不在 StoryBoard 上,因为它是通过编程方式创建的。我该如何解决这个问题?
【问题讨论】: