0
我想知道如何在沒有使用故事板的情況下以編程方式進行操作,並且能夠製作一個按鈕,當它按下時會將您引導至另一個viewController。Swift:創建導致新視圖的按鈕
我想知道如何在沒有使用故事板的情況下以編程方式進行操作,並且能夠製作一個按鈕,當它按下時會將您引導至另一個viewController。Swift:創建導致新視圖的按鈕
let button = UIButton(type: UIButtonType.System)
button.setTitle("Button", forState: UIControlState.Normal)
button.sizeToFit()
button.addTarget(self, action: "loadViewController", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
loadViewController是在你的控制器的方法加載另一個視圖控制器。
func loadViewController()
{
let vc = UIViewController(nibName: "ViewController", bundle: nil)
self.presentViewController(vc, animated: true, completion:nil)
}