Untitled
unknown
swift
a year ago
5.2 kB
5
Indexable
// // ChatEventMessages.swift // JILLII // // Created by Kishan on 28/11/23. // import UIKit class ChatEventMessages: UIViewController { @IBOutlet weak var tblEventMessageListing: UITableView! @IBOutlet weak var viewSearch: UIView! @IBOutlet weak var txtFieldSearch: UITextField! var arrEventChatListing = [CreatePost]() var filterdArrEventChatListing = [CreatePost]() var objEventDetail:EventDetail? override func viewDidLoad() { super.viewDidLoad() self.tblEventMessageListing.register(UINib(nibName: "EventNameTBLCell", bundle: nil), forCellReuseIdentifier: "EventNameTBLCell") } override func viewWillAppear(_ animated: Bool) { DispatchQueue.main.async { self.arrEventChatListing.removeAll() self.JSONAllMessageList() self.tblEventMessageListing.reloadData() self.viewSearch.setCornerRadius_Extension(20.0) } } @IBAction func onTapBack(_ sender: UIButton) { self.navigationController?.popViewController(animated: true) } } extension ChatEventMessages:UITableViewDelegate,UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.filterdArrEventChatListing.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "EventNameTBLCell", for: indexPath) as! EventNameTBLCell let dicEvent = self.filterdArrEventChatListing[indexPath.row] cell.selectionStyle = .none DispatchQueue.main.async { cell.chatEventSetup(dicEvent: dicEvent) } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return UITableView.automaticDimension; } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let dict = self.filterdArrEventChatListing[indexPath.row] var eventData = EventDetail(["title" : dict.title, "icon" : dict.icon, "id" : dict.id]) if dict.is_host == "0" { let vc = StoryBoard.Activity.instantiateViewController(withIdentifier: "ChatDetailVC") as! ChatDetailVC vc.isThemeYellow = false vc.isFromEventMessage = true vc.isEventGroup = true vc.arrEventChatListing = dict vc.isFromRsvp = true vc.objRsvpData = eventData self.navigationController?.pushViewController(vc, animated: true) }else{ let vcEventConv = StoryBoard.EventDetail.instantiateViewController(withIdentifier: "EventMessageVC") as! EventMessageVC vcEventConv.objEventDetail = eventData vcEventConv.isFromEventMessage = true self.navigationController?.pushViewController(vcEventConv, animated: true) } } } //Api Calling extension ChatEventMessages { func JSONAllMessageList() { var param = [String:Any]() WebService.shared.RequesURL(ServerURL.all_event_chats_list , Perameters: param, showProgress: true, completion: { (response, status) in print(response) if let arrEventTypeGet = response.object(forKey: "data") as? [[String:Any]] { print(arrEventTypeGet) self.arrEventChatListing = arrEventTypeGet.map({CreatePost.init($0)}) self.filterdArrEventChatListing = self.arrEventChatListing self.tblEventMessageListing.reloadData() } else { ShowAlert(title: enumAlert.Alert.rawValue, message: ToString(response["message"]), buttonTitle: "Ok", handlerCB: nil) } }) { (err) in debugPrint(err.localizedDescription) ShowAlert(title: enumAlert.Alert.rawValue, message: ToString(err.localizedDescription), buttonTitle: "Ok", handlerCB: nil) } } } extension ChatEventMessages : UITextFieldDelegate { func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let searchText = (textField.text! as NSString).replacingCharacters(in: range, with: string) filterContentForSearchText(searchText) return true } func filterContentForSearchText(_ searchText: String) { if searchText.isEmpty { // If search text is empty, show all contacts self.filterdArrEventChatListing = self.arrEventChatListing } else { // Filter contacts based on search text filterdArrEventChatListing = self.arrEventChatListing.filter { contact in return contact.title.lowercased().contains(searchText.lowercased()) } } // Reload table view self.tblEventMessageListing.reloadData() } }
Editor is loading...
Leave a Comment