代码之家  ›  专栏  ›  技术社区  ›  M. Kremer

iOS 8中的layoutMarginsFollowReadableWidth错误

  •  0
  • M. Kremer  · 技术社区  · 9 年前

    我开发了一个应用程序,它在iOS 9中运行得很好,但如果我使用静态UITableViewCell打开控制器,则会出现以下错误:

    由于未捕获的异常“NSUnknownKeyException”而终止应用,原因:“[setValue:forUndefinedKey:]:此类不符合键布局MarginsFollowReadableWidth的键值编码。”

    我检查了是否存在“空”连接,但没有。

    这是ViewController的代码:

    class KontaktController: UITableViewController, MFMailComposeViewControllerDelegate{
    
        @IBOutlet weak var mapView: MKMapView!
        @IBOutlet weak var openMenu: UIBarButtonItem!
    
        let mailController = MFMailComposeViewController()
    
        override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            switch UIDevice.currentDevice().userInterfaceIdiom {
            case .Phone:
                // It's an iPhone
                switch indexPath.section{
                case 0:
                    return 150
                case 3:
                    if indexPath.row == 0{
                        return 150
                    }
                    else{
                        return 100
                    }
                default:
                    return 53
                }
            case .Pad:
                // It's an iPad
                switch indexPath.section{
                case 0:
                    return 250
                case 3:
                    if indexPath.row == 0{
                        return 250
                    }
                    else{
                        return 100
                    }
                default:
                    return 53
                }
            default:
                print("OH ?!")
                // Uh, oh! What could it be?
            }
    
          return 10
        }
    
    
        @IBAction func kontaktirenSieUnsPressed(sender: AnyObject) {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let user = PFUser.currentUser()
            if user != nil{
                if user?.username != nil {
    
                    let viewController: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("anfrage_Navigation") as! UINavigationController
                    let addVC =  storyboard.instantiateViewControllerWithIdentifier("neue_anfrage") as! AddAnfrageController
    
    
    
                    revealViewController().pushFrontViewController(viewController, animated: true)
                    viewController.pushViewController(addVC, animated: true)
                    return
                    //rootViewController.pushViewController(viewController, animated: true)
                }
            }
    
            let logInViewController = storyboard.instantiateViewControllerWithIdentifier("LogIn")
            self.presentViewController(logInViewController, animated: false, completion: nil)
        }
        @IBAction func adressPressed(sender: UIButton) {
    
            switch sender.tag{
            case 0:
                let url: NSURL = NSURL(string: "tel://004965185730")!
                UIApplication.sharedApplication().openURL(url)
            case 2:
                let mailComposeViewController = configuredMailComposeViewController()
                if MFMailComposeViewController.canSendMail() {
                    self.presentViewController(mailComposeViewController, animated: true, completion: nil)
                } else {
                    self.showSendMailErrorAlert()
                }
            case 3:
                let url: NSURL = NSURL(string: "http://www.dachdecker-kremer.de")!
                UIApplication.sharedApplication().openURL(url)
            default:
                print("")
            }
        }
    
        override func viewDidLoad() {
            // SWReveal Button:
            // Menu öffnen
            openMenu.target = self.revealViewController()
            openMenu.action = Selector("revealToggle:")
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    
            let regionRadius: CLLocationDistance = 500
            let location = CLLocation(latitude: 49.743056, longitude:  6.621047)
            let region = MKCoordinateRegionMakeWithDistance(location.coordinate,
                regionRadius * 2.0, regionRadius * 2.0)
            mapView.setRegion(region, animated: false)
    
            // Banner:
            let anotation = MKPointAnnotation()
            anotation.coordinate = CLLocationCoordinate2D(latitude: 49.743056, longitude: 6.621047)
            anotation.title = "Dachdecker Kremer"
            mapView.addAnnotation(anotation)
    
        }
    
    
    
        // Send email:
        func configuredMailComposeViewController() -> MFMailComposeViewController {
            let mailComposerVC = MFMailComposeViewController()
            mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
    
            mailComposerVC.setToRecipients(["info@dachdecker-kremer.de"])
    
            mailComposerVC.setMessageBody("Gesendet von der Dachdecker Kremer App.", isHTML: false)
    
            return mailComposerVC
        }
    
        func showSendMailErrorAlert() {
            let sendMailErrorAlert = UIAlertController(title: "E-mail senden fehlgeschlagen", message: "Ihr iPhone kann leider keine Mails senden. Gehen Sie zu Einstellungen/Mail, um den Fehler zu beheben.", preferredStyle: .Alert)
            sendMailErrorAlert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
            self.presentViewController(sendMailErrorAlert, animated: true, completion: nil)
        }
    
        // MARK: MFMailComposeViewControllerDelegate Method
        func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
            controller.dismissViewControllerAnimated(true, completion: nil)
        }
        @IBAction func route(sender: AnyObject) {
            let targetURL = NSURL(string: "http://maps.apple.com/?daddr=49.743056,6.621047&dirflg=d&t=h")
            UIApplication.sharedApplication().openURL(targetURL!)
        }
    
    }
    

    我希望你们中的一些人知道是什么导致了这个错误。

    1 回复  |  直到 9 年前
        1
  •  1
  •   zeaa    9 年前

    我在Xcode项目中也遇到了这个问题,并最终解决了它。 错误为:“由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键布局MarginsFollowReadableWidth的键值编码。”

    原因是我在尺寸检查器选项中使用了“添加尺寸类自定义”,将其删除并再次运行,错误消失了。希望对你有所帮助。 As is shown in picture