Tag: 快速

自动调整uitableviewcell – SWIFT

我正在尝试resize的UILabel,可以是一个或多个行的tableviewcell。 我需要为应用程序的其余部分打开自动布局,所以我不想closures它来实现这个工作。 目标是iOS 7和iOS 8。 我已经尝试了几种解决scheme,但由于某种原因,我似乎无法获得标签的正确高度来自动调整或调整单元格高度。 问题发生在这个方法中:calculateHeightForConfiguredSizingCell。 我已经在Git上做了一个示例项目,所以你可以看到我所看到的。 https://github.com/mdaymond/cellResizer 这个例子是基于这篇文章: http : //www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout 更新我检查了代码的更新。 它几乎是以我想要的方式工作,并以编程方式进行计算,但由于某些原因,标签高度的大小并不正确 – 它没有达到所需的全部高度。 原始代码的问题是标签需要明确的宽度。

视图加载之前,位置不更新

我有一个variables“zipCode”,我试图更新到用户当前位置的视图加载在我的scrollView。 目前,当我退出并回到scrollView视图控制器时,它会更新到正确的位置。 此外,我应该实施全新安装授权更新的更改。 感谢您的帮助。 import UIKit import CoreLocation var zipCode = 90210 var location = [""] class ViewController: UIViewController, CLLocationManagerDelegate { let locationManager = CLLocationManager() @IBOutlet var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() self.locationManager.delegate = self self.locationManager.desiredAccuracy = kCLLocationAccuracyBest self.locationManager.requestWhenInUseAuthorization() self.locationManager.startUpdatingLocation() } ////Current Location func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: { […]

Swift:委托协议没有正确设置UILabel

我有以下Protocol : protocol SoundEventDelegate{ func eventStarted(text:String) } 我在这堂课中所称的: class SoundEvent { var text:String var duration:Double init(text: String, duration: Double){ self.text = text self.duration = duration } var delegate : SoundEventDelegate? func startEvent(){ delegate?.eventStarted(self.text) } func getDuration() -> Double{ return self.duration //TODO is this common practice? } } 我有我的ViewController符合: class ViewController: UIViewController, SoundEventDelegate { //MARK:Properties @IBOutlet […]

在Swift for iOS 7.1中解压.sks文件

我有一个应用程序,它使用以下扩展名从iOS 8中的.sks文件很好地加载: class func unarchiveFromFile(file : NSString) -> SKNode? { if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks") { var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)! var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData) archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene") let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene archiver.finishDecoding() return scene } else { return nil } } 但是,当我在运行iOS 7.1的设备上使用它时,我在AppDelegate上获得了一个EXC_BAD_ACCESS代码EXC_I386_GPFLT,并在日志中获得了这个代码: […]

如何在导航栏或其他屏幕内容上方创build视图?

我希望在导航栏上方有一个视图,或者在屏幕上没有导航栏的情况下,在任何屏幕上方显示视图,以便实质上减less其他所有内容的高度,但不包含任何内容。 我也希望这种观点允许交互(即如果它的挖掘,它会做一些事情)。 我已经尝试了UIApplication.sharedApplication().keyWindow?.addSubview(view)但是只覆盖了视图。 这是一个可视化:

如何在Swift中知道发件人的标识符

我有一个UITableViewCell有两个UITapGestureRecognizers 。 cell.Username.tag = indexPath.row cell.SharedUser.tag = indexPath.row let tapGestureRecognizer2 = UITapGestureRecognizer(target:self, action:"GoToProfil:") let tapGestureRecognizer3 = UITapGestureRecognizer(target:self, action:"GoToProfil:") cell.Username.userInteractionEnabled = true cell.Username.addGestureRecognizer(tapGestureRecognizer2) cell.SharedUser.userInteractionEnabled = true cell.SharedUser.addGestureRecognizer(tapGestureRecognizer3) func GoToProfil (sender: AnyObject!) { self.performSegueWithIdentifier("GoToProfilSegue", sender: sender) } 我使用Segue来推送另一个UIViewController ,并且我重写PrepareSegue函数来发送对应于Sender标签的所需信息。 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { let ProfilView = segue.destinationViewController as! Profil ProfilView.hidesBottomBarWhenPushed = true ProfilView.title = […]

根据对应于特定属性的另一个数组中的值对对象数组sorting

比方说从JSON API中检索一个对象数组: [ { "id": 48, "name": "Bob" }, { "id": 198, "name": "Dave" }, { "id": 2301, "name": "Amy" }, { "id": 990, "name": "Colette" } ] // eg for ease of reproduction: let dataObjects = [ ["id": 48, "name": "Bob"], ["id": 198, "name": "Dave"], ["id": 2301, "name": "Amy"], ["id": 990, "name": "Colette"] ] […]

Swift枚举:正常/不可破坏的初始化不支持 – 或只是破碎?

我已经阅读了关于Swift的failable初始化程序的文档,但没有看到任何关于正常的,不可分类的变种的明确信息。 我是否错过了一些东西,或者是普通初始值设定项不支持具有原始值的枚举值,即使初始值设定项没有可能失败(因为初始值设定项默认为默认值): enum FailableSeason : Int { init?(d: Int) { switch (d % 365) { case 60…151: self = .Spring case 152…243: self = .Summer case 244…334: self = .Fall // default provided, guaranteed to be valid default: self = .Winter } } case Spring case Summer case Fall case Winter } enum ImplicitlyUnwrappedFailableSeason : […]

使用Swift连接/断开Chromecast设备

我最近开始用苹果新语言Swift开发Chromecast应用程序。 但我坚持要与Chromecast设备build立连接。 到目前为止,它可以在networking上看到Chromecast。 之后会出现一个AlertController(一个AlertController与ActionSheet相同)我使用AlertController的原因是,因为ActionSheet被Apple弃用。 起初,我认为这将是ActionSheet,使其无法正常工作。 之后,我尝试了不同版本的ActionController / ActionSheet,但没有运气到目前为止。作为在Swift中创build这个的参考,我使用了Google Cast示例应用程序Objective C中的什么。https://github.com/ googlecast / CastHelloText-IOS – 更新 – Alertcontrollerpopup后,我点击一个设备,然后连接并成功。 当我试图断开它给我一个exception错误“ 意外地发现零,而解包可选值 ”。 我在这行代码中得到这个错误。 self.mediaInformation.metadata.stringForKey(kGCKMetadataKeyTitle) 所以基本上是说mediaInformation = nil, self.mediaInformation.metadata.stringForKey(kGCKMetadataKeyTitle!) 所以我认为让它成为可选的,但没有奏效。 有谁知道为什么它不工作? func chooseDevice() { if selectedDevice == nil { let alertController = UIAlertController(title: "Choose an device..", message: "Click on your chromecast!", preferredStyle: .ActionSheet) for device in deviceScanner.devices { […]

被取消初始化时,Unowned引用是否设置为“nil”?

我很快就对这个话题感到困惑,因为无主的引用必须总是有一个值,不能是可选的,也就是说它们不能被设置为'nil'….好吧,我只是在Apple文档中看到一个程序对于swift而言,对实例“B”的无主引用的实例“A”被去初始化并且在实例“B”被去初始化/释放之后解除分配……当var被去初始化/ dealloc并不意味着它们是设为'无'? 实例B是一个可选的,所以确保它可以容纳'零',但为什么实例'A'被取消初始化,当它应该总是有一个值? PS:如果这有帮助…..实例'B'是一个可选的types,强烈的引用实例'A'