Tag: swift

在更新UITableView的时候,会丢失新的可见行的Missing单元格

我在删除一行时遇到了崩溃。 // Updating my data model …. // apply the updates self.tableView.beginUpdates() self.tableView.deleteRows(at: indexPathsToDelete, with: .automatic) self.tableView.endUpdates() 重现步骤 – 添加行 – 删除行,具体确保当前屏幕之外有一些行(当删除成功时屏幕将显示在屏幕上) – 重复直到崩溃发生 它不总是发生,所以我最好的猜测是,只有当它试图加载的单元格被回收时才会发生 这是在Xcode 8.0的10.0模拟器中 *** Assertion failure in -[UITableView _updateWithItems:updateSupport:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/UITableView.m:3149 Missing cell for newly visible row 2 (null) 代码为cellForRowAt if isMultipe{ let cell = tableView.dequeueReusableCell(withIdentifier: DetailsTableViewCell.defaultIdentifier, for: indexPath) as! DetailsTableViewCell return […]

在Swift中从App启动App Store

我正在创build一个应用程序,我有一个横幅,促进我的其他应用程序。 这是我的代码: var barsButton : UIButton = UIButton(frame: CGRectMake((self.view.bounds.width / 2) – 51, self.view.bounds.height – 100, 102, 30)) barsButton.setImage(UIImage(named: "Bars Icon 2.png"), forState: .Normal) barsButton.addTarget(self, action: "openBarsLink", forControlEvents: UIControlEvents.TouchUpInside) func openBarsLink() { var barsLink : String = "itms-apps:https://itunes.apple.com/app/bars/id706081574?mt=8" UIApplication.sharedApplication().openURL(NSURL.URLWithString(barsLink)) } 但是,当用户按下button时,它只是把他们带到App Store,而不是我的应用程序的特定页面。 我究竟做错了什么?

XCode 6.3 MKPointAnnotation setCoordinate缺失

我只是更新了XCode到6.3,现在我收到以下错误:MKPointAnnotation没有名为“setCoordinate”的成员。 不知道它去了哪里,或者如果我们应该使用一些其他的MK方法。 任何帮助表示赞赏。 func refreshlocation(lat:String, lon:String, withOffset:Bool = false){ // 1 Convert the string values to something that can be used. let location = CLLocationCoordinate2D( latitude: (lat as NSString).doubleValue as CLLocationDegrees, longitude: (lon as NSString).doubleValue as CLLocationDegrees ) // 2 setup some initial variables. let span = MKCoordinateSpanMake( (self.locationLatitudeDelta as NSString).doubleValue as CLLocationDegrees, (self.locationLongitudeDelta as […]

将CLLocationCoordinate2D放入Swift的CLLocation中

我有一个方法,我想调用,但是当我回到地图的中心,它是在CLLocationCoordinate2Dtypes。 如何将CLLocationCoordinate2D的结果放入CLLocation中?

Xcode错误:调用-display没有效果

每当我加载我的SpriteKit应用程序,它会logging此错误: <CAMetalLayer: 0x15f57fa70>: calling -display has no effect. ,并没有正确显示许多对象。 我已经尝试重新创build场景并删除我的代码,两者都没有做任何事情。 有一段时间,我认为这可能是一个新的Xcode 7和iOS 9testing版的错误,但现在,我已经尝试了两者的GM版本,问题依然存在,可能并非如此。

如何通过在Swift中从UIScrollViewinheritanceUITextView来制作垂直UITextView?

背景 我是iOS开发的新手,但为了使用垂直的蒙古文脚本开始制作最基本的应用程序,我需要一个垂直的UITextView 。 我还没有find任何其他蒙古应用程序开发人员共享他们的代码,所以我试图自己做。 蒙古文是从上到下写的,行从左到右换行,如下图所示: 滚动应该是水平的(从左到右)。 在前面的问题中,我提出了一个镜像字体和UITextView的旋转和镜像的组合(因为这是我在Android中所做的)。 然而,在阅读了这个答案并对iOS做事方式(比如使用TextKit )做了进一步的研究后,我认为从头开始创build像UIVerticalTextView这样的东西可能会更好,而不是像普通的UITextView 。 而且由于我从UIScrollView中看到UITextView inheirits ,我假设我应该UIVerticalTextView UIScrollView来创buildUIVerticalTextView 。 我现在在哪里 我上面提到的答案是UIView子类,但是我在滚动工作方面遇到了很多麻烦。 这是我想要UIScrollView另一个原因。 此外,解决scheme没有重新排列每一行中的文字,当有方向改变时。 我已经收集了以下几部分,但我不知道如何把它们放在一起: NSTextStorage – 这不应该有任何不同。 它将只存储蒙古的Unicode文本和任何样式信息。 NSTextContainer – 高度和宽度需要切换为垂直文本容器大小。 (无论如何,我认为是这样,除非在其他地方可以这样做)。 NSLayoutManager – 有什么特别的需要在这里完成,或由UIVerticalTextView ? UIVerticalTextView – 这将是UIScrollView的子类,但是需要添加和/或覆盖哪些方法? class UIVerticalTextView: UIScrollView { // Which properties to include? // – TextStorage // – TextContainer // – LayoutManager // which […]

应用程序崩溃发布版本,但不是在debugging

正如我在标题中所说,我正在为iPhone编写一个应用程序,它在debugging模式下完美运行,但是当我将它构build为发行版并通过TestFlight安装时,它会崩溃。 由于崩溃日志,它可能不得不采取以下措施: let path = NSBundle.mainBundle().pathForResource("PrinterList", ofType: "plist") if path != nil { let printerDic = NSDictionary(contentsOfFile: path!) let printerList = NSArray(array: printerDic.allKeys) printerNames = printerList as [String] } 我正在使用Brother的框架打印没有AirPrint,但我认为这不是问题,因为应用程序崩溃之前做一些框架。 它只在这个ViewController中崩溃,我执行这些行。 我只需要在这个ViewController的框架。

WKWebView内容加载function永远不会被调用

我试图得到一个函数,我的内容WKWebView完全加载后调用。 我在Apple Swift WKNavigation文档中find了“didFinishNavigation”函数。 func webView(webView: WKWebView!, didFinishNavigation navigation: WKNavigation!) { println("WebView content loaded.") } 但是这个函数永远不会被调用。 import UIKit import WebKit class ViewController: UIViewController WKNavigationDelegate { override func loadView() { super.loadView() self.webView = WKWebView(frame:self.containerView.frame, configuration: WKWebViewConfiguration()) self.containerView.addSubview(webView!) self.containerView.clipsToBounds = true } override func viewDidLoad() { super.viewDidLoad() var url = NSURL(string:"http://google.com/") var req = NSURLRequest(URL:url) self.webView!.loadRequest(req) } […]

如何从Swift中的UIView中删除所有的手势识别器

我写了试图从给定的自定义UIViewtypes的所有子视图中删除所有手势识别器的Swift代码。 let mySubviews = self.subviews.filter() { $0.isKindOfClass(CustomSubview) } for subview in mySubviews { for recognizer in subview.gestureRecognizers { subview.removeGestureRecognizer(recognizer) } } 但是for recognizer器行会产生编译器错误: '[AnyObject]?' does not have a member named 'Generator' 我已经尝试更改for recognizer循环以for recognizer in enumerate(subview.gestureRecognizers)器,但会产生编译器错误: Type '[AnyObject]?!' Does not conform to protocol 'SequenceType' 我看到UIView的gestureRecognizers方法返回[AnyObject]?? ,而且我认为双重包装的回报价值正在让我失望。 谁能帮我? 更新:修改,编译代码是: if let recognizers = subview.gestureRecognizers { for […]

设置UIImagePicker的委托返回错误

在我为OCR翻译应用程序编写的代码中遇到问题。 代码片段如下: @IBAction func btnOCR(sender: AnyObject) { var languageAlert = UIAlertController(title: "For Your Information…", message: "The OCR feature currently only supports English & French.", preferredStyle: .Alert) languageAlert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: { action in var image = UIImagePickerController() image.sourceType = UIImagePickerControllerSourceType.Camera image.allowsEditing = false image.delegate = self presentViewController(image, animated: true, completion: nil) })) self.presentViewController(languageAlert, animated: […]