2016-05-17 13 views
0

Ich habe einen UIAlertController wie folgt:Wie behandelt man `UIAlertController` richtig, wenn die Quellansicht geändert wird?

let menu = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) 

menu.popoverPresentationController?.sourceView = someView! 
menu.popoverPresentationController?.sourceRect = someView!.bounds 

Es funktioniert gut, bis ich das Gerät drehen. (IPAD nur, weil für IPAD, die UIAlertController zeigt ein popover an einer Position in Abhängigkeit von sourceView und sourceRect)

Wenn ich das Gerät dreht, wird die Position/Größe des durch ein anderes Modul verändert. Daher gibt es einige Warnungen über contraints:

Unable to simultaneously satisfy constraints. 

Obwohl es nur warnen, ich hoffe immer noch zu wissen, was der richtige Weg ist UIAlertController zu handhaben, wenn die Quelle Ansicht geändert wird?

EDIT: Protokolle für die Einschränkung Warnungen:

Unable to simultaneously satisfy constraints. 
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
"<NSAutoresizingMaskLayoutConstraint:0x7fac14c672f0 UIView:0x7fac14c994c0.width == 19>", 
"<NSLayoutConstraint:0x7fac14c95260 UIView:0x7fac1483b430.width == 300>", 
"<NSLayoutConstraint:0x7fac124f8520 _UIAlertControllerView:0x7fac14c41cc0.width == UIView:0x7fac14c994c0.width>", 
"<NSLayoutConstraint:0x7fac14c09ac0 _UIAlertControllerView:0x7fac14c41cc0.width >= UIView:0x7fac1483b430.width>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fac14c95260 UIView:0x7fac1483b430.width == 300> 
+0

Welche Einschränkungen sind falsch genau? Können Sie uns den Code zeigen, der den Fehler erzeugt? – Sulthan

+0

was willst du erreichen? –

+0

@Sultan siehe EDIT Teil –

Antwort

-1

Versuchen Sie es mit folgenden Es funktioniert

@IBAction func actionContinueToPay(sender: UIButton) { 
     let optionMenu = UIAlertController(title: "Select payment method", message: "Select the payment method first", preferredStyle: .ActionSheet) 

     let cashOnDeliveryAction = UIAlertAction(title: "Cash On delivery", style: .Default, handler: { 
      (alert: UIAlertAction!) -> Void in 
      // self.serviceCallSaveOrder() 
      self.serviceCallSaveOrder("No Token",STATUS: self.STATUS_COD) 

     }) 



     let walletAction = UIAlertAction(title: "Pay by Card", style: .Default, handler: { 
      (alert: UIAlertAction!) -> Void in 
      self.serviceCall_GetcardInfo() 

     }) 

     let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { 
      (alert: UIAlertAction!) -> Void in 
      print("Canrcelled") 
     }) 
     optionMenu.addAction(cashOnDeliveryAction) 
     optionMenu.addAction(walletAction) 

     optionMenu.addAction(cancelAction) 

     self.presentViewController(optionMenu, animated: true, completion: nil) 

    } 
Verwandte Themen