我开发了一个在iOS 9中运行良好的应用程序,但是如果我使用静态UITableViewCell打开控制器,则会出现此错误:
由于未捕获的异常"NSUnknownKeyException"而终止应用,原因:"[ setValue:forUndefinedKey:]:此类不符合键布局边距跟随可读宽度的键值编码。
我检查了是否有"空"连接,但没有。
这是视图控制器的代码:
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!)
}
}
我希望你们中的一些人知道导致此错误的原因。
我在 Xcode 项目中也遇到了这个问题,最终解决了它。错误是:"由于未捕获的异常'NSUnknownKeyException'而终止应用,原因为:"[ setValue:forUndefinedKey:]:此类不符合键布局边距跟随可读宽度的键值编码。
原因是我在尺寸检查器选项中使用"添加尺寸类自定义",将其删除并再次运行,错误消失了。希望对您有所帮助。如图所示