【发布时间】:2021-04-12 03:45:26
【问题描述】:
最初我可以在 tableview 中显示所有行。现在我只需要显示搜索到的文本字段行...
这里的文本字段和搜索按钮在表格视图之外。现在如果我在文本字段中添加日期并点击搜索按钮,那么我只需要在表格视图中显示包含行的日期如何做到这一点
在 tableview 中显示所有行的代码: postedServicesCall 参数的 from_date 为 nil 然后我需要显示所有行 .. 我可以用下面的代码来做这件事 .. 现在如何显示from_date 中是否有值,那么只有日期包含在 tableview 中的行
class PageContentViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var fromDateTextField: MDCTextField!
private var servicesArray = [ServicesModel]()
override func viewDidLoad() {
postedServicesCall()
DispatchQueue.main.async {
self.servicesTableView.reloadData()
}
}
func postedServicesCall(){
let param = ["from_date" : ""]
APIReqeustManager.sharedInstance.serviceCall(param: param as [String : Any], method: .post, loaderNeed: false, loadingButton: nil, needViewHideShowAfterLoading: nil, vc: self, url: CommonUrl.posted_requests, isTokenNeeded: true, isErrorAlertNeeded: true, isSuccessAlertNeeded: false, actionErrorOrSuccess: nil, fromLoginPageCallBack: nil) { [weak self] (resp) in
self?.postedServicesData = Posted_services_base_model(dictionary: resp.dict as NSDictionary? ?? NSDictionary())
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return servicesArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ServicesTableViewCell", for: indexPath) as! ServicesTableViewCell
cell.serviceTitle.text = servicesArray[indexPath.row].title
cell.dateLabel.text = servicesArray[indexPath.row].date
cell.locationLabel.text = servicesArray[indexPath.row].location
return cell
}
//if i add date in textfield and tap on search.. then with the date how many rows are there should be display in tableview
@IBAction func searchtBtn(_ sender: TransitionButton) {
}
如果我在文本字段中搜索日期,那么我需要在 tableview 中显示与日期相关的行。如何?
请帮忙写代码
【问题讨论】:
-
你听说过swift中的Filter方法吗?用它来过滤Array,然后重新加载TableView
标签: json swift uitableview uitextfield