看看这个示例代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let letterButton = UIButton.buttonWithType(.Custom) as UIButton
self.view.addSubview(letterButton)
letterButton.addTarget(self, action:Selector("buttonDidTap:"), forControlEvents: .TouchUpInside)
}
func buttonDidTap(button: UIButton!) {
print(button.char)
}
}
Run Code Online (Sandbox Code Playgroud)
UIButton
只要Selector是公共的或内部的,工作的目标操作就可以了,但是如果它是私有的,它会因为无法识别的选择器发送到实例而崩溃
有什么办法可以实现吗?我不想公开或内部使用tap功能.
刚开始学习iOS AutoLayout,界面构建器非常直接,但是当我尝试在代码上存档相同的东西时
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(==2)-[_nextKeyboardButton]-(==2)-[_numPadButton]-(==2)-[_spaceButton]-(==2)-[_returnButton]-(==2)-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_nextKeyboardButton,_numPadButton,_spaceButton,_returnButton)]];
Run Code Online (Sandbox Code Playgroud)
它提出了一个例外,
无法同时满足约束.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x6000000966c0 H:|-(2)-[UIButton:0x7fe4f1d1c760'Next'] (Names: '|':UIInputView:0x7fe4f1f04d00 )>", …
Run Code Online (Sandbox Code Playgroud)