- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我有一个自定义搜索栏(即 TextField
)来搜索来自 API 的数据。搜索数据显示在 TextField
下方的 TableView
中。
当我点击搜索结果时,它应该在 ViewController`即我的 homecontroller 文件中显示其详细数据
搜索 Controller 代码:
class SearchPageController: UIViewController {
@IBOutlet weak var searchTxtBar: UITextField!
@IBOutlet weak var searchTblView: UITableView!
var searchData = [ModelSearched]()
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboardWhenTappedAround()
// Do any additional setup after loading the view.
searchTxtBar.delegate = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
//MARK: IBActions
@IBAction func toHomeScreen(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
func getSearchList(){
let params: Parameters=[
"search":"\(self.searchTxtBar.text ?? "")",
]
if ApiUtillity.sharedInstance.isReachable()
{
ApiUtillity.sharedInstance.StartProgress(view: self.view)
APIClient<ModelBaseSearchList>().API_GET(Url: SD_GET_SearchList, Params: params as [String:AnyObject], Authentication: true, Progress: true, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (modelResponse) in
ApiUtillity.sharedInstance.StopProgress(view: self.view)
if(modelResponse.success == true) {
if self.searchTxtBar.text!.count != 0 {
self.searchData.removeAll()
}
let resul_array_tmp_new = modelResponse.searched! as NSArray
if resul_array_tmp_new.count > 0 {
for i in modelResponse.searched! {
self.searchData.append(i)
}
}
}
else {
self.view.makeToast(modelResponse.message)
}
ApiUtillity.sharedInstance.StopProgress(view: self.view)
self.searchTblView.reloadData()
}) { (failed) in
ApiUtillity.sharedInstance.StopProgress(view: self.view)
self.view.makeToast(failed.localizedDescription)
}
}
else
{
self.view.makeToast("No Internet Connection..")
}
}
@IBAction func clearSearchData(_ sender: UIButton) {
self.searchData.removeAll()
self.searchTxtBar.text = ""
searchTblView.reloadData()
}
}
//MARK: Tableview delegates and datasource methods
extension SearchPageController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if searchData.count == 0 {
tableView.setEmptyView(message: "Try searching categories/store data..", messageImage: UIImage(named: "magnifier")!)
}else {
tableView.restore()
}
return searchData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "catstoredata")
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: "catstoredata")
}
let dict = searchData[indexPath.row]
cell?.selectionStyle = .none
cell?.textLabel?.text = dict.name
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
self.navigationController?.popViewController(animated: true)
}
}
//MARK: textfield delegates method
extension SearchPageController: UITextFieldDelegate{
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.searchTxtBar.resignFirstResponder()
self.searchTblView.reloadData()
return true
}
func textFieldDidEndEditing(_ textField: UITextField) {
self.getSearchList()
}
}
主页 Controller ,我希望在其中显示搜索到的数据:
class HomeViewController: UIViewController {
var couponsData = [ModelCoupons]()
var colorList = [UIColor]()
var selectedIds = [Int]()
@IBOutlet var logoutPopup: UIView!
@IBOutlet weak var homeTblView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
//append colors
colorList.append(UIColor(rgb: 0xdd191d))
colorList.append(UIColor(rgb: 0xd81b60))
colorList.append(UIColor(rgb: 0x8e24aa))
colorList.append(UIColor(rgb: 0x5e35b1))
colorList.append(UIColor(rgb: 0x3949ab))
colorList.append(UIColor(rgb: 0x4e6cef))
colorList.append(UIColor(rgb: 0x00acc1))
colorList.append(UIColor(rgb: 0x00897b))
colorList.append(UIColor(rgb: 0x0a8f08))
colorList.append(UIColor(rgb: 0x7cb342))
colorList.append(UIColor(rgb: 0xc0ca33))
colorList.append(UIColor(rgb: 0xfdd835))
colorList.append(UIColor(rgb: 0xfb8c00))
colorList.append(UIColor(rgb: 0xf4511e))
colorList.append(UIColor(rgb: 0xf4511e))
colorList.append(UIColor(rgb: 0x757575))
colorList.append(UIColor(rgb: 0x546e7a))
self.homeTblView.register(UINib(nibName: "HomeCell", bundle: nil), forCellReuseIdentifier: "HomeCell")
self.homeTblView.register(UINib(nibName: "Home1Cell", bundle: nil), forCellReuseIdentifier: "Home1Cell")
self.post_CouponsData()
self.homeTblView.reloadData()
print(selectedIds)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
func changeDateForamte(dateString: String, currentDateFormate: String, newDateFormate: String) -> String
{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = currentDateFormate
let newDate = dateFormatter.date(from: dateString)
dateFormatter.dateFormat = newDateFormate
return dateFormatter.string(from: newDate!)
}
@IBAction func logout_yes(_ sender: Any) {
Defaults.remove(.udk_IS_LOGIN)
let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.navigationController?.pushViewController(vc, animated: true)
}
@IBAction func logout_no(_ sender: Any) {
self.logoutPopup.removeFromSuperview()
}
@objc func openDeals(sender: UIButton) {
if sender.tag == 12 {
DispatchQueue.global().async {
let svc = SFSafariViewController(url: URL(string: self.couponsData[sender.tag].subUrl!)!)
self.present(svc, animated: true, completion: nil)
DispatchQueue.main.async(execute: {
let svc = SFSafariViewController(url: URL(string: self.couponsData[sender.tag].guid!)!)
self.present(svc, animated: true, completion: nil)
})
}
}else {
DispatchQueue.global().async {
let svc = SFSafariViewController(url: URL(string: self.couponsData[sender.tag].subUrl!)!)
self.present(svc, animated: true, completion: nil)
DispatchQueue.main.async(execute: {
let svc = SFSafariViewController(url: URL(string: self.couponsData[sender.tag].guid!)!)
self.present(svc, animated: true, completion: nil)
})
}
}
}
//MARK: IBActions
@IBAction func toCategoryScreen(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
@IBAction func toSearchPage(_ sender: UIButtonX) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "SearchPageController") as! SearchPageController
self.navigationController?.pushViewController(vc, animated: true)
}
@IBAction func logoutBtnPressed(_ sender: Any) {
ApiUtillity.sharedInstance.AddSubViewtoParentView(parentview: self.view, subview: logoutPopup)
}
func post_CouponsData() {
if ApiUtillity.sharedInstance.isReachable() {
var params = [String : String]()
params ["term_ids"] = "\(self.selectedIds.map(String.init).joined(separator: ","))"
ApiUtillity.sharedInstance.StartProgress(view: self.view)
APIClient<ModelBaseCouponsList>().API_POST(Url: SD_POST_CouponsList, Params: params as [String:AnyObject], Authentication: true, Progress: true, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (modelResponse) in
ApiUtillity.sharedInstance.StopProgress(view: self.view)
if(modelResponse.success == true) {
ApiUtillity.sharedInstance.StopProgress(view: self.view)
let dict = modelResponse.coupons
for i in dict! {
self.couponsData.append(i)
}
}else {
self.view.makeToast(modelResponse.message)
}
ApiUtillity.sharedInstance.StopProgress(view: self.view)
self.homeTblView.reloadData()
}) { (failed) in
self.view.makeToast(failed.localizedDescription)
ApiUtillity.sharedInstance.StopProgress(view: self.view)
}
}else {
self.view.makeToast("No internet connection...")
ApiUtillity.sharedInstance.StopProgress(view: self.view)
}
}
}
extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return couponsData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let couponObj = couponsData[indexPath.row]
if couponObj.postImage!.count != 0 {
if couponObj.subUrl!.isEmpty {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeCell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let path = Bundle.main.path(forResource: "loader1", ofType: "gif")!
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
cell.home_image.kf.indicatorType = .image(imageData: data)
cell.home_image.kf.setImage(with: URL(string: couponObj.postImage!), placeholder: UIImage(named: "placeholder"), options: [.transition(.fade(0.2))])
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
if let couponTitle = couponObj.coupon_code, couponTitle.count != 0 {
cell.couponView.isHidden = false
cell.seeproductView.isHidden = false
cell.goToDealBtn.isHidden = true
cell.couponTitle.text = couponObj.coupon_code
}else {
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.couponTitle.text = "N/A"
}
cell.seeProductBtnTapped.tag = 12
cell.seeProductBtnTapped.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
}else if couponObj.subUrl!.isEmpty && couponObj.coupon_code!.isEmpty {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeCell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let path = Bundle.main.path(forResource: "loader1", ofType: "gif")!
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
cell.home_image.kf.indicatorType = .image(imageData: data)
cell.home_image.kf.setImage(with: URL(string: couponObj.postImage!), placeholder: UIImage(named: "placeholder"), options: [.transition(.fade(0.2))])
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.goToDealBtn.tag = 13
cell.goToDealBtn.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
}else {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeCell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let path = Bundle.main.path(forResource: "loader1", ofType: "gif")!
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
cell.home_image.kf.indicatorType = .image(imageData: data)
cell.home_image.kf.setImage(with: URL(string: couponObj.postImage!), placeholder: UIImage(named: "placeholder"), options: [.transition(.fade(0.2))])
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.goToDealBtn.tag = 13
cell.goToDealBtn.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
}
} else {
if couponObj.subUrl!.isEmpty {
let cell = tableView.dequeueReusableCell(withIdentifier: "Home1Cell", for: indexPath) as! Home1Cell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
if let couponTitle = couponObj.coupon_code, couponTitle.count != 0 {
cell.couponView.isHidden = false
cell.seeproductView.isHidden = false
cell.goToDealBtn.isHidden = true
cell.couponTitle.text = couponObj.coupon_code
}else {
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.couponTitle.text = "N/A"
}
cell.seeProductBtnTapped.tag = 12
cell.seeProductBtnTapped.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
} else if couponObj.subUrl!.isEmpty && couponObj.coupon_code!.isEmpty{
let cell = tableView.dequeueReusableCell(withIdentifier: "Home1Cell", for: indexPath) as! Home1Cell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.goToDealBtn.tag = 13
cell.goToDealBtn.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
}else {
let cell = tableView.dequeueReusableCell(withIdentifier: "Home1Cell", for: indexPath) as! Home1Cell
if let postTitle = couponObj.postTitle, postTitle.count != 0 {
cell.ticket_postTitle.text = postTitle
}
if let postContent = couponObj.postContent, postContent.count != 0 {
cell.ticket_postContent.text = postContent
}
let randomInt = Int(arc4random()) % colorList.count
cell.ticketImageView.tintColor = colorList[randomInt]
cell.ticket_ValidDate.text = self.changeDateForamte(dateString: couponObj.validTill!, currentDateFormate: "yyyy-MM-dd", newDateFormate: "dd MMMM yyyy")
cell.couponView.isHidden = true
cell.seeproductView.isHidden = true
cell.goToDealBtn.isHidden = false
cell.goToDealBtn.tag = 13
cell.goToDealBtn.addTarget(self, action: #selector(self.openDeals), for: .touchUpInside)
return cell
}
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "CouponDetailVC") as! CouponDetailVC
let indexPath = tableView.indexPathForSelectedRow
vc.couponData = couponsData[indexPath!.row]
self.navigationController?.pushViewController(vc, animated: true)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let couponObj = couponsData[indexPath.row]
if couponObj.postImage!.count != 0 {
return 334.0
}else {
return UITableView.automaticDimension
}
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
let couponObj = couponsData[indexPath.row]
if couponObj.postImage!.count != 0 {
return 334.0
}else {
return UITableView.automaticDimension
}
}
}
最佳答案
在您的SearchPageController中,创建以下函数。
func gotoHomeVC(_ data: Int) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
if !vc.selectedIds.isEmpty {
vc.selectedIds.removeAll()
}
vc.selectedIds.append(data)
self.navigationController?.pushViewController(vc, animated:true)
}
然后在您的 SearchPageController 的 tableView:didSelectRowAtIndexPath: 中将您的代码替换为以下代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath {
tableView.deselectRow(at: indexPath, animated: true)
guard let data = searchData[indexPath.row].iD else {return}
self.gotoHomeVC(data) // call the function here
}
关于swift - 单击时在先前的 ViewController 上显示搜索详细数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56842026/
我在选项卡中有我的网络应用程序的选项。 aaa bbb ccc ddd eee 当用户单击任何选项卡(在同一窗口中)时,我会使用此代码获得淡出效果,然后自动
如何获得一个简单的调用单击来实现如下功能:http://jsfiddle.net/ftwPS/6/我显然错过了一些基本的东西,因为当您单击“CLICK”时这不起作用。 $('tr').click(fu
我有一个列表,在左侧显示一个插入符号图标,单击它时应该更改图标。每当我单击一个图标时,所有图标都会更改。 detailedInfo = []; subordinateInfo; openSu
我有一个 div,我想对其进行设置,以便当我单击其他内容时,它会隐藏该 div。 我也是这样 $('body').click(function(){ if(loginOpened) {
我有很多装有不同内容的盒子。 如果单击第一个框,您可以看到一个包含更多详细信息的弹出框。如果单击第二个、第三个等框,您必须查看这些框的详细信息。 我的问题:如果我点击框号。 2 我看到了盒子号的详细信
当我点击 .add-btn 时,我将 .add-btn 的样式更改为 background:#cccccc 并将 val() 更改为“-”。 现在当我用 tr td .list 删除添加的文本时,它是
感谢 SO 的出色贡献者!当您开始了解 jQuery 时,它会变得更酷。 :) 所以我有一个 LI,单击时会显示/隐藏子 UL。我想做的是能够单击 LI 内的链接,打开一个空白窗口,但也不会关闭子 U
我有这份文档,它使我能够获得一份带有点击进度的多项选择选择调查问卷。 如何用图像代替此处的文字? (并且仍然有这样的机制,一旦单击[图像],就会提出下一个问题) 我已经尝试使用 UL/H1 设置背景图
我想在 JQGrid 的刷新按钮单击上编写代码。有什么事件吗? 最佳答案 如果您需要在开始刷新之前执行一些操作,您应该使用 beforeRefresh打回来: $("#grid_id").jqGrid
问题是将对象或多个参数从模板传递到组件,并使用它们将数据添加到 API。 任务.service.ts addTasks(task: Task): Observable{ let headers =
我有一个像这样的primefaces选项卡 View : This tab has static content. this t
我在 jquery 中有一个有效的 a.click() 函数...但是如果我单击一个 anchor ,我会打开一个新窗口...但是我怎样才能阻止浏览器本身打开一个新窗口? 示例: $('a')
有没有简单的方法来创建代码:如果 URL 更改或单击链接显示 div(例如加载 gif 3 秒),则显示页面?有点像空白的白色页面,加载 gif 旋转 3 秒然后显示页面? 谢谢! 最佳答案 给定 G
我需要知道此时按钮的状态是否被点击? 谢谢 最佳答案 if (myButton.state & UIControlStateHighlighted) { // Do your stuff the
我正在 NSImageView 上绘制一条 NSBezierPath 线。我正在创建 NSBezierPath 对象,设置 moveToPoint,设置 lineToPoint,设置 setLineW
我的 Selenium 代码存在问题,无法正确执行按键 + 单击操作。 测试应打开 jqueryui.com 链接并选择页面上的前 2 个 li 元素。 我正在使用 Selenium 2.23 和 F
单击时我将更改字符串一部分的样式。例如“TEXT”,然后单击“T”,之后它会将样式从黑色更改为红色,仅 T在我的代码中,当我单击文本时,我拆分文本并保留在“split”数组中,它将调用handleCl
我在网站上有一个 anchor 。当有人点击它时,我在 jquery 中执行一些操作并更改名称,但是当再次单击它时,事件被触发,尽管我已经更改了它的名称。代码在这里: $(".like_cont a[
我有一个下载链接Download我希望每次当有人点击“下载”时,我都可以将其插入数据库total_downloads+1。为了插入数据库,我通常使用 然后 if (isset($_POST['d
我是一名优秀的程序员,十分优秀!