在我的代码中,我有一个UITextField,当用户点击时打开一个UIDatePicker,使用户能够轻松有效地滚动到他们的出生日期.显然,我们不希望UIDatePicker像目前那样向上滚动到2015年及以上.因为它是出生日期输入字段,我还需要能够将条目限制为16年+.我该怎么做呢?
class SignUpViewController: UIViewController, UITextFieldDelegate {
var datePicker:UIDatePicker!
@IBOutlet weak var dateTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// UI DATE PICKER SETUP
var customView:UIView = UIView(frame: CGRectMake(0, 100, 320, 160))
customView.backgroundColor = UIColor.clearColor()
datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320, 160))
datePicker.datePickerMode = UIDatePickerMode.Date
customView.addSubview(datePicker)
dateTextField.inputView = customView
var doneButton:UIButton = UIButton (frame: CGRectMake(100, 100, 100, 44))
doneButton.setTitle("Done", forState: UIControlState.Normal)
doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInside)
doneButton.backgroundColor = UIColor .grayColor()
dateTextField.inputAccessoryView = doneButton
Run Code Online (Sandbox Code Playgroud) 在最近更新Xcode之后,以前工作的代码不再有效.大多数选择器(":")都有自动更正,但此代码除外:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}
Run Code Online (Sandbox Code Playgroud)
标记错误:
没有使用Objective C选择器'keyboardWillSHow:'声明的方法
此图像显示了所有失败的尝试.
这段代码的新语法是什么?
我正在尝试在注册视图控制器中创建profilePic.profilePic的类型为UIImageView.我希望能够点击它,以便立即在ActionSheet样式中提取照片库.并且还有一个图像框一个按钮来访问相机.这可能吗?
import UIKit
class SignUpViewController: UIViewController, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var profilePic: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// PROFILE PICTURE
let tapGesture = UITapGestureRecognizer(target: self, action: "imageTapped:")
profilePic.addGestureRecognizer(tapGesture)
profilePic.userInteractionEnabled = true
}
func imageTapped(gesture:UIGestureRecognizer) {
if let profile1Pic = gesture.view as? UIImageView {
print("Image Tapped")
}
}
Run Code Online (Sandbox Code Playgroud) swift ×3
xcode ×2
keyboard ×1
nsdate ×1
swift2.2 ×1
uidatepicker ×1
uiimageview ×1
uitextfield ×1
xcode7 ×1