Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // TableViewControllerSearch.swift
- // A43App
- //
- // Created by Yuri Boschetto on 20/11/2019.
- // Copyright © 2019 Bosyu. All rights reserved.
- //
- import UIKit
- import Alamofire
- import SwiftyJSON
- class TableViewControllerSearch: UITableViewController,UISearchBarDelegate {
- var indicator : UIActivityIndicatorView!
- var arrayImmagini = [[String:AnyObject]]()
- var swiftyJSON: JSON!
- @IBOutlet weak var searchBar1: UISearchBar!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Uncomment the following line to preserve selection between presentations
- // self.clearsSelectionOnViewWillAppear = false
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.rightBarButtonItem = self.editButtonItem
- self.searchBar1.delegate = self
- self.tableView.delegate = self
- self.tableView.dataSource = self
- self.indicator = UIActivityIndicatorView(style: .gray)
- view.addSubview(indicator)
- self.indicator.center = CGPoint(x: view.frame.size.width*0.5, y: view.frame.height*0.5)
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- // #warning Incomplete implementation, return the number of sections
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of rows
- return arrayImmagini.count
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)-> UITableViewCell{
- let cell = self.tableView.dequeueReusableCell(withIdentifier: "cellaSearch") as! TableViewCellSearch
- let imageID = arrayImmagini[indexPath.row]["ImmagineID"] as! String
- let email = arrayImmagini[indexPath.row]["Email"] as! String
- let testo = arrayImmagini[indexPath.row]["Testo"] as! String
- let image1 = arrayImmagini[indexPath.row]["FileName"] as! String
- // let imageFileExtension = ".jpg"
- let url2 = URL(string: "http://www.bosyu.altervista.org/Uploads/"+image1)
- let data = try? Data(contentsOf: url2!)
- cell.labelTop.text = email
- cell.labelBottom.text = testo
- cell.imageView1.image = UIImage(data: data!)
- let imageRatio = cell.scaleImage(image: cell.imageView1.image!)
- tableView.rowHeight = tableView.frame.width/imageRatio+150
- return cell
- }
- func searchBarSearchButtonClicked(_ searchBar: UISearchBar){
- var textS = self.searchBar1.text!
- textS = textS.replacingOccurrences(of: " ",with:"%20",options: .literal, range: nil)
- let url = "http://bosyu.altervista.org/Ricerca.php?Testo="+textS
- self.indicator.startAnimating()
- Alamofire.request(url).responseJSON{
- response in
- switch response.result {
- case .success:
- self.swiftyJSON=JSON(response.result.value!)
- self.arrayImmagini=self.swiftyJSON["immagini"].arrayObject as! [[String:AnyObject]]
- self.tableView.reloadData()
- self.indicator.stopAnimating()
- case .failure:
- print(response)
- self.indicator.stopAnimating()
- }
- }
- }
- /*
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
- // Configure the cell...
- return cell
- }
- */
- /*
- // Override to support conditional editing of the table view.
- override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the specified item to be editable.
- return true
- }
- */
- /*
- // Override to support editing the table view.
- override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
- if editingStyle == .delete {
- // Delete the row from the data source
- tableView.deleteRows(at: [indexPath], with: .fade)
- } else if editingStyle == .insert {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- */
- /*
- // Override to support rearranging the table view.
- override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
- }
- */
- /*
- // Override to support conditional rearranging of the table view.
- override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the item to be re-orderable.
- return true
- }
- */
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement