2017-01-26 2 views
0

Mein Programm stürzt jedes Mal ab, wenn der Compiler versucht, eine Webansicht zu erstellen, nachdem einige Daten vom Json-Objekt abgerufen wurden. Es ist mit diesem Fehler abgestürzt:UIWebview-Absturz mit Fehler: EXC_BREAKPOINT (CODE = EXC_I386_BPT, SUBCODE = 0X0)

EXC_BREAKPOINT (CODE=EXC_I386_BPT, SUBCODE = 0X0)

Hinweis: jedes anderes Objekt (UIlabel, UIButton, UItextfield usw.) erfolgreich ohne das Programm abstürzt erstellt wird, nur die UIWEBView bewirkt, dass das Programm zum Absturz bringen.

enter image description here

Hier ist der Code:

getdata(){ (boolValue) ->() in 
     self.loadimg() 
     self.reloadInputViews() 
     SwiftLoading().hideLoading() 
    } 
} 

func loadimg() 
{ 
    for L in 0..<Basketpic.count{ 

     var webv = UIWebView() 
     let link = NSURL(string:Basketpic[L]) 
     let requestObj = NSURLRequest(url: link! as URL) as URLRequest 
     webv.loadRequest(requestObj) 
     webv.contentMode = .scaleToFill 
     webv.frame = CGRect(x: 280 , y:100 + (120 * L), width: 90, height: 100) 

     /*let webv = UIWebView() 
     let link = NSURL(string:Basketpic[L]) 
     let requestObj = NSURLRequest(url: link! as URL) as URLRequest 
     webv.loadRequest(requestObj) 
     webv.contentMode = .scaleToFill 
     webv.frame = CGRect(x: 280 , y:100 + (120 * L), width: 90, height: 100)*/ 

     /*let name = UILabel() 
     name.text = (BasketNames[L]) 
     name.contentMode = .scaleToFill 
     name.frame = CGRect(x: 140 , y: 100 + (120 * L), width: 150, height: 100) 

     let price = UILabel() 
     price.text = (String(BasketPrices[L])) 
     price.contentMode = .scaleToFill 
     price.frame = CGRect(x: 55 , y: 100 + (120 * L), width: 100, height: 100)*/ 

     // view.addSubview(name) 
     // view.addSubview(price) 
     // view.addSubview(webv) 
    } 

    /* let sum = BasketPrices.reduce(0, +) 
    let total = UILabel() 
    total.text = (String(sum)) 
    total.contentMode = .scaleToFill 
    let L = BasketPrices.count 
    total.frame = CGRect(x: 55 , y: 100 + (120 * L), width: 100, height: 100) 

    let totall = UILabel() 
    totall.text = ("المجموع الكلي") 
    totall.contentMode = .scaleToFill 
    totall.frame = CGRect(x: 155 , y: 100 + (120 * L), width: 100, height: 100) 

    view.addSubview(totall) 
    view.addSubview(total) */ 
} 

func getdata(completion: @escaping (_ result: Bool)->()) 
{ 
    let listUrlString = "http://burjuman.net/kkkls/basketreview.php" 
    let myUrl = URL(string: listUrlString); 
    var request = URLRequest(url:myUrl!) 
    request.httpMethod = "GET"; 

    let task = URLSession.shared.dataTask(with: request as URLRequest) { 
     data, response, error in 
     do { 
      let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String:AnyObject] 
      if let result = json["result"] as? [[String: AnyObject]] { 
       for blog in result { 
        if let basket = blog["basket"] as? String { 
         if let id = blog["id"] as? String { 
          if let userid = blog["User_Id"] as? String { 
           if(userid == "75") 
           { 
            Basketpic.append(basket) 
            print(userid) 
            print(id) 
            print(basket) 
           } 
          } 
         } 
        } 
       } 
      } 
     } catch { 
      print("error serializing JSON: \(error)") 
     } 
     print(Basketpic) 
     completion (true) 
    } 
    task.resume() 
} 
+0

Try Dispatching alles, was die Benutzeroberfläche in den Hauptthread ändert. –

Antwort

0

nach einer Anfrage UI-Element anzuzeigen, benötigen Sie zu verwenden:

(In swift3)

DispatchQueue.main.async { 
    /* What you want to display, update label, show webview */ 
} 
+0

Vielen Dank .. es hat funktioniert –

Verwandte Themen