我正在尝试实现一个TableView,它覆盖一个UITextViews InputView,为用户提供一个可搜索的TableView,该TableView然后用所选的值填充UITextField。
我已经搜索了一些,我找到的最接近的解决方案是this,但我不知道如何将UITableViewController与我的UITextViews InputView联系起来?
我可以看到这些函数在MultiSelectPicker中被调用.
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
override func numberOfSectionsInTableView(tableView: UITableView) -> Int但是这些不是,我很肯定地解释了为什么我没有看到任何填充在表视图中的东西。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 我已经更改了didSet,所以我知道reloadData是从主线程调用的,但仍然什么也没有。
var items = [NSObject](){
didSet{
dispatch_async(dispatch_get_main_queue(),{
self.tableView.reloadData()
});
}
}这可能与我在主视图控制器中设置inputView的方式有关,但我对iOS和Swift相当陌生,所以我可能缺少一些基本的东西。
@IBOutlet weak var mspEmployee: MultiSelectPicker!
let employeePickerView = MultiSelectPicker()
employeePickerView.items = self.oEmployees
self.mspEmployee = employeePickerView
self.txtEmployee.inputView = self.mspEmployee.view这实在是快把我逼疯了,所以任何帮助都会很感激!
发布于 2016-04-20 15:21:38
您需要对UITextField进行子类化,并将inputView设置为UITableView视图。以下是我最近所做的类似事情的一些实现。
class BaseTextField: UITextField{
//Base textfield so that all custom textfields inherit the disabling of certain uitextfield things
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//disabling menu, autocorrection and copy paste functionality
autocorrectionType = UITextAutocorrectionType.No
inputAssistantItem.leadingBarButtonGroups = []
inputAssistantItem.trailingBarButtonGroups = []
}
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
NSOperationQueue.mainQueue().addOperationWithBlock { () -> Void in
UIMenuController.sharedMenuController().setMenuVisible(false, animated: false)
}
return false
}
}
class OptionSelectText: BaseTextField{
let picker:OptionPicker //this is the UITableViewController I Use for selecting values
required init?(coder aDecoder: NSCoder) {
picker = OptionPicker()
picker.view.translatesAutoresizingMaskIntoConstraints = false
super.init(coder: aDecoder)
picker.delegate = self
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: picker.view.frame.width, height: 44))
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(OptionSelectText.pickerViewDoneAction))
let flex = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: self, action: nil)
let clearButton = UIBarButtonItem(title: "Clear", style: UIBarButtonItemStyle.Plain, target:self, action: #selector(OptionSelectText.pickerClearAction))
toolbar.setItems([clearButton, flex, doneButton], animated: false)
toolbar.userInteractionEnabled = true
inputView = picker.view
inputAccessoryView = toolbar
}
}https://stackoverflow.com/questions/36722185
复制相似问题