Tag: swift

延迟使用instantiateViewControllerWithIdentifier但不执行SegueWithIdentifier?

下面的代码用于将另一个视图控制器推到导航堆栈上。 当使用instantiateViewControllerWithIdentifier ,segue在第一次(〜3秒)明显缓慢,但是在随后的每一次都会相当快地发生。 其他SOpostbuild议确保代码完成的主线程上发生,但这并没有解决问题。 但是,使用performSegueWithIdentifier不会造成延迟。 SendViewController的viewDidLoad代码对于第一次和后续的推送是相同的。 尝试删除viewDidLoad目标视图控制器,但仍存在instantiateViewControllerWithIdentifier滞后,但不执行performSegueWithIdentifier 。 如何解决与instantiateViewControllerWithIdentifier延迟? 没有延迟: @IBAction func buttonTapped(sender: UIButton) { performSegueWithIdentifier(SendSegue, sender: self) } 第一次显示SendViewController时导致延迟: @IBAction func buttonTapped(sender: UIButton) { dispatch_async(dispatch_get_main_queue()) { let vc = self.storyboard!.instantiateViewControllerWithIdentifier(self.SendViewControllerID) as! SendViewController self.navigationController!.pushViewController(vc, animated: true) } }

-canOpenURL:URL失败:“fbauth2:/”(OSStatus错误-10814。)“

我在我的应用程序中添加了Facebook和Google注册,但是我有这个问题 操作无法完成。 -10814 在Facebooklogin,我不知道如何解决它,这是我的应用程序委托代码为openUrl : func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { if let fbSDKAppId = FBSDKSettings.appID(), url.scheme!.hasPrefix("fb\(fbSDKAppId)"), url.host == "authorize" { var shouldOpen :Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!,annotation:options[UIApplicationOpenURLOptionsKey.annotation]) return shouldOpen } else { return GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:]) } } 我可以做什么?

隐藏另一个button时居中一个button的约束

我有一个视图控制器上的两个button。 它们高度和宽度相等,间隔很好,以屏幕为中心。 问题是,在某些情况下,其中一个button是隐藏的。 当其中一个button被隐藏时,我想让另一个button居中。 对于我的生活,我一直无法弄清楚如何configuration约束来实现这一点。 我可以移动可见button,使其居中,如果另一个button被隐藏,但似乎只能加载视图后,这使得button“跳”,看起来很愚蠢。

添加多个数组形成一个最终的数组。 debuggingswift xcode

我正在尝试创build一个flashcard应用程序。 我成功地获得了应用程序的地方,有11个不同的闪存卡arrays,所有这些arrays添加到一个最终arrays,然后我可以通过刷卡。 正如你所看到的,每个组在其结尾处都有“active:true”。 这是因为我有一个设置页面来打开和closures每个单词组。 import UIKit class SecondViewController: UIViewController , UIGestureRecognizerDelegate { @IBAction func home(_ sender: Any) { performSegue(withIdentifier: "home", sender: self) } @IBOutlet weak var imgPhoto: UIImageView! struct List { let words: [String] var active: Bool } let list1 = List(words:["lake", "lamb", "lamp", "lark", "leaf", "leash", "left", "leg", "lime", "lion", "lips", "list", "lock", "log", […]

Swift – “使用未parsing的标识符”

我在学Swift! 我想在xib上创build主界面。 但有错误“使用未解决的标识符”。 从MainViewController添加代码 import Foundation public class MainViewController : BaseViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) // TODO: Write your test code here // … } } UPD:(添加图片)

将NSAttributedString转换为数据进行存储

我有一个UITextView属性文本和allowsEditingTextAttributes设置为true 。 我试图将属性的string转换成一个数据对象,使用下面的代码: let text = self.textView.attributedText let data = try text.data(from: NSMakeRange(0, text.length), documentAttributes: [:]) 但是,这是抛出以下错误: Error Domain=NSCocoaErrorDomain Code=66062 "(null)" 任何想法这个错误意味着什么或可能导致这种情况? 我在最新的Xcode和iOS上。 谢谢。

如何使用swift在iOS应用程序中以编程方式计算Parse类中的行?

我有一个parsing后端为我的iOS应用程序。 我有一个称为“测验”的parsing类。 如何读取Parse类中的行数,我必须在iOS应用程序中使用它? 我正在使用下面的代码,但xcode不input代码块。 var cnt = 1 var query = PFQuery(className:"quiz") query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) -> Void in if error == nil { // The find succeeded. print("Successfully retrieved \(objects!.count) scores.") cnt = objects!.count } else { // Log details of the failure print("Error: \(error!) \(error!.userInfo)") } } return cnt 谢谢!

如何在Swift中使用MKPolylineView

我想在Swift应用程序中绘制折线。 SWIFT代码 class MapViewController: UIViewController, MKMapViewDelegate { @IBOutlet var theMapView: MKMapView override func viewDidLoad() { super.viewDidLoad() setMapView() } func setMapView() { //theMapView.zoomEnabled = false //theMapView.scrollEnabled = false theMapView.rotateEnabled = false // var lat: CLLocationDegrees = 37.586601 var lng: CLLocationDegrees = 127.009381 // var latDelta: CLLocationDegrees = 0.008 var lngDelta: CLLocationDegrees = 0.008 var theSpan: MKCoordinateSpan […]

多个URL的NSFileManager Swift数组

我将如何去添加多个url? 我不知道如何能迅速地将它设置成一个数组。 if let audioUrl = NSURL(string: "http://freetone.org/ring/stan/iPhone_5-Alarm.mp3") { println("LOADING AUDIO") if let myAudioDataFromUrl = NSData(contentsOfURL: audioUrl){ println("AUDIO LOADED") let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let destinationUrl = documentsUrl.URLByAppendingPathComponent(audioUrl.lastPathComponent!) println(destinationUrl) if NSFileManager().fileExistsAtPath(destinationUrl.path!) { println("The file already exists at path") } else { if myAudioDataFromUrl.writeToURL(destinationUrl, atomically: true) { println("file saved") } else { println("error […]

如何从PFGeopoint(Parse.com和Swift)检索位置,并使用Xcode 6.2在地图上显示

这里有一些答案,但涉及到不同的问题,都在客观的c。 我用这个保存在一个用户的parsing类“职位”职位: var locationManager = CLLocationManager() var lat = locationManager.location.coordinate.latitude var lon = locationManager.location.coordinate.longitude let myGeoPoint = PFGeoPoint(latitude: lat, longitude:lon) let myParseId = PFUser.currentUser().objectId //PFUser.currentUser().objectId println("****** this is my geoPoint: \(myGeoPoint)") func sendPosition(userOfPosition: User) { let takePosition = PFObject(className: "Position") takePosition.setObject(myParseId, forKey: "who") //who takePosition.setObject(myGeoPoint, forKey: "where") takePosition.saveInBackgroundWithBlock(nil) } sendPosition(currentUser()!) 所以这是我的结果: 那么我想在地图上显示他们,但是怎么样? 不明白如何从“where”列中取回经纬度,下面的代码不起作用: import UIKit […]