2015-09-30 41 views
0

下午好,的UIView里面的UIView与文本字段和按钮无效

我试图展现一个UIView时(对我来说)没有任何结果充满了产品的tableView显示。当我检测到0个产品时,我展示了一个UIView,其中包含一个Label,一个TextField和一个Button,但我无法与TextField进行交互,也无法与Button进行交互。

这是我第一次使用这种技术来显示一个UIView,当tableView发生问题时,所以我想知道我的代码中有什么问题,以及我错过了什么,因为它真的很奇怪。

这里是我的代码(当我打印“找不到产品”是我展示了UIView):提前

import UIKit 
import Social 

class ProductoCamViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 

@IBOutlet var productoImageView:UIImageView! 
@IBOutlet var tableView:UITableView! 

@IBOutlet weak var noEncontrado:UIView! 

var productoImage:String! 

var ean:String! 

var producto:Producto! 

var productos = [Producto]() 

@IBOutlet weak var toolBar: UIToolbar! 

@IBOutlet weak var cargando: UIActivityIndicatorView! 

override func viewDidLoad() { 

    toolBar.hidden = true 

    noEncontrado.hidden = true 

    cargando.hidden = false 

    super.viewDidLoad() 

    // Set table view background color 
    self.tableView.backgroundColor = UIColor(red: 240.0/255.0, green: 240.0/255.0, blue: 240.0/255.0, alpha: 0.2) 

    // Remove extra separator 
    self.tableView.tableFooterView = UIView(frame: CGRectZero) 

    // Change separator color 
    self.tableView.separatorColor = UIColor(red: 240.0/255.0, green: 240.0/255.0, blue: 240.0/255.0, alpha: 0.8) 

    self.tableView.rowHeight = UITableViewAutomaticDimension 
    self.tableView.estimatedRowHeight = 88.0 

    requestPost() 

    cargando.hidden = true 

    tableView.reloadData() 
} 

override func viewDidAppear(animated: Bool) { 
    tableView.reloadData() 
} 

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 

    self.navigationController?.hidesBarsOnSwipe = false 
    self.navigationController?.setNavigationBarHidden(false, animated: true) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

func requestPost() { 

    let request = NSMutableURLRequest(URL: NSURL(string: "http://www.mywebsite.com/product.php")!) 
    request.HTTPMethod = "POST" 
    let postString = "ean="+ean 

    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) 
    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { 
     data, response, error in 

     if error != nil { 
      print("error=\(error)") 
      return 
     } 

     // JSON RESULTADO ENTERO 
     let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)! 

     if (responseString == "Product not found") 
     { 
      self.noEncontrado.hidden = false 
      self.tableView.reloadData() 
      return 
     } 
     else 
     { 
      self.productos = self.parseJsonData(data!) 

      self.toolBar.hidden = false 

      // Reload table view 
      dispatch_async(dispatch_get_main_queue(), { 
       self.tableView.reloadData() 
      }) 
     } 
    } 
    task.resume() 
} 

func parseJsonData(data: NSData) -> [Producto] { 
    var productos = [Producto]() 

    do { 
     let jsonResult = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary 

     noEncontrado.hidden = true 
     // Parse JSON data 
     let jsonProductos = jsonResult?["lista_productos"] as! [AnyObject] 

     for jsonProducto in jsonProductos { 

      let producto = Producto() 
      producto.imagen = jsonProducto["imagen"] as! String 
      producto.nombre = jsonProducto["nombre"] as! String 
      producto.descripcion = jsonProducto["descripcion"] as! String 
      producto.modo_de_empleo = jsonProducto["modo_de_empleo"] as! String 
      producto.marca = jsonProducto["marca"] as! String 
      producto.linea = jsonProducto["linea"] as! String 
      producto.distribuidor = jsonProducto["distribuidor"] as! String 
      producto.tamano = jsonProducto["tamano"] as! String 
      producto.precio = jsonProducto["precio"] as! String 
      producto.codigo_nacional = jsonProducto["codigo_nacional"] as! String 

      productos.append(producto) 
     } 
    } 
    catch let parseError { 
     print(parseError) 
    } 

    return productos 
} 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // Return the number of sections. 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // Return the number of rows in the section. 
    return productos.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    title = productos[indexPath.row].nombre 

    let cell = tableView.dequeueReusableCellWithIdentifier("CellDetail", forIndexPath: indexPath) as! ProductoTableViewCell 

    cell.selectionStyle = .None 

    if let url = NSURL(string: productos[indexPath.row].imagen) { 
     if let data = NSData(contentsOfURL: url) { 
      self.productoImageView.image = UIImage(data: data) 
     } 
    } 

    cell.nombre.text = productos[indexPath.row].nombre 
    cell.descripcion.text = productos[indexPath.row].descripcion 
    cell.modo_de_empleo.text = productos[indexPath.row].modo_de_empleo 
    cell.marca.text = productos[indexPath.row].marca 
    cell.linea.text = productos[indexPath.row].linea 
    cell.distribuidor.text = productos[indexPath.row].distribuidor 
    cell.tamano.text = productos[indexPath.row].tamano 
    cell.precio.text = productos[indexPath.row].precio 
    cell.codigo_nacional.text = productos[indexPath.row].codigo_nacional 

    cell.layoutIfNeeded() 

    return cell 
} 
} 

感谢。

+0

您是否尝试在您显示的uiview上将enableUserInteraction设置为true? – Miknash

+0

是的,这两个UIView都启用了userInteraction。谢谢@NickCatib –

+0

当你显示这个UIView时,我建议你在xcode中使用Debug View Hiearchy。有了这个,你可以看到任何视图是否阻止了你的UITextField或UIButton。 –

回答

2

起初,请尽量提供英文代码:)但无论如何。我认为应该出现的观点是nonEncontrado。 可能有一些问题,但我需要看故事板。

  1. 视图有userInteraction未启用。它是一个属性,也可以在故事板中激活
  2. 视图被其他内容覆盖。也许是空的tableView。

作为一个建议,你可以在tableView中提供这些字段,并加载另一个数据源。比你不需要打额外的意见。如果你从故事板提供屏幕,我可以帮助更多。 祝您好运:)

+0

谢谢@BjörnRo,这是第二种情况,我只是在显示新的UIView时隐藏tableView,然后它工作:)非常感激和道歉的代码不是英文的一点点我试图改变它,但它是很多代码。问候。 –

+0

伟大的,我可以帮助。祝你有美好的一天;) –