iOS 从 iPhone 更改为通用后应用程序崩溃:
iOS App Crashes After Changing From iPhone to Universal:
我收到来自 xCode 的错误消息:
2015-11-03 12:25:04.833 New Application[1122:1104042] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x14f68cb50>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
*** First throw call stack:
(0x182e1cf5c 0x19799ff80 0x188c50068 0x1886c0254 0x1886be384 0x18861c844 0x188628de4 0x1883651e4 0x182dd3c30 0x182dd19d4 0x182dd1e04 0x182d00dc0 0x18dca8088 0x1883daf60 0x1000f0d00 0x1981be8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
上线:
class AppDelegate: UIResponder, UIApplicationDelegate {
在:
//
// AppDelegate.swift
// FlappyBird
//
// Created by Nate Murray on 6/2/14.
// Copyright (c) 2014 Fullstack.io. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
在此处找到:
我的来源:
https://github.com/androiddeveloperfl/SADiver
原始出处:
https://github.com/fullstackio/FlappySwift/blob/master/FlappyBird/AppDelegate.swift
非常感谢任何suggestions/answers/solutions。
当您在 iPad 上调用一个动作 sheet 时,它是一个弹出窗口。这意味着您必须声明弹出箭头将指向的位置。获取警报的弹出窗口显示控制器并在显示警报时向其提供此信息。
这是一个例子:
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
func handler(act:UIAlertAction!) {
print("User tapped \(act.title)")
}
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: handler))
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: handler))
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: handler))
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: handler))
self.presentViewController(alert, animated: true, completion: nil)
// if we do no more than that, we'll crash on iPad
// here's how to fix that:
if let pop = alert.popoverPresentationController {
let b = sender as! UIBarButtonItem
pop.barButtonItem = b // or set sourceView and sourceRect
}
当您尝试在 SplashViewController
中执行操作 sheet 时,应用程序崩溃了。在 iPad 上,一个动作 sheet 有一个小箭头指向触发弹出窗口的控件或视图,您需要告诉它指向哪里。在你的代码中,在 alert(title: String, message: String)
函数中你可以做类似的事情;
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0)
这会将箭头放在视图的中心。这可能看起来很奇怪,所以您可能还想将 UIAlertController 的样式从 action sheet 更改为 alert:
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
我觉得哪个更好看。然后你不需要关于 popoverPresentationController
的行
我收到来自 xCode 的错误消息:
2015-11-03 12:25:04.833 New Application[1122:1104042] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x14f68cb50>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
*** First throw call stack:
(0x182e1cf5c 0x19799ff80 0x188c50068 0x1886c0254 0x1886be384 0x18861c844 0x188628de4 0x1883651e4 0x182dd3c30 0x182dd19d4 0x182dd1e04 0x182d00dc0 0x18dca8088 0x1883daf60 0x1000f0d00 0x1981be8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
上线:
class AppDelegate: UIResponder, UIApplicationDelegate {
在:
//
// AppDelegate.swift
// FlappyBird
//
// Created by Nate Murray on 6/2/14.
// Copyright (c) 2014 Fullstack.io. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
在此处找到:
我的来源: https://github.com/androiddeveloperfl/SADiver
原始出处:
https://github.com/fullstackio/FlappySwift/blob/master/FlappyBird/AppDelegate.swift
非常感谢任何suggestions/answers/solutions。
当您在 iPad 上调用一个动作 sheet 时,它是一个弹出窗口。这意味着您必须声明弹出箭头将指向的位置。获取警报的弹出窗口显示控制器并在显示警报时向其提供此信息。
这是一个例子:
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
func handler(act:UIAlertAction!) {
print("User tapped \(act.title)")
}
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: handler))
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: handler))
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: handler))
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: handler))
self.presentViewController(alert, animated: true, completion: nil)
// if we do no more than that, we'll crash on iPad
// here's how to fix that:
if let pop = alert.popoverPresentationController {
let b = sender as! UIBarButtonItem
pop.barButtonItem = b // or set sourceView and sourceRect
}
当您尝试在 SplashViewController
中执行操作 sheet 时,应用程序崩溃了。在 iPad 上,一个动作 sheet 有一个小箭头指向触发弹出窗口的控件或视图,您需要告诉它指向哪里。在你的代码中,在 alert(title: String, message: String)
函数中你可以做类似的事情;
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0)
这会将箭头放在视图的中心。这可能看起来很奇怪,所以您可能还想将 UIAlertController 的样式从 action sheet 更改为 alert:
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
我觉得哪个更好看。然后你不需要关于 popoverPresentationController