Tag: 快速

如何检测用户在Swift中的不活动?

我需要实现一个空闲超时function。 要做到这一点,我只需要知道如何检测用户触摸屏幕(类似于Android中使用的onUserInteraction方法)。 那么我怎么才能发现用户与ViewController交互的时候呢? PS:如果我问这是因为你在互联网上找不到什么好东西!

添加字典时避免重复

我有一个字典,我正在添加像这样的值… var mydictionary = ["id": "", "quantity": "","sellingPrice":""] as [String : Any] dictionary["id"] = product?.id dictionary["quantity"] = product?.quantity dictionary["sellingPrice"] = product?.theRate 而我把这些值添加到像这样的数组… self.arrayOfDictionary.append(mydictionary) 但是,如果arrayOfDictionary已经包含mydictionary ,我不想添加它。 否则,我想添加它。 这里的基本思想是将集合视图项中的数据添加到字典数组中。 当我点击每个集合查看项目上的button时,数据就被添加到字典数组中。 同时在tableviewcell中显示这些数据。 但是,当我从tableview中导航并再次访问collectionview项目并单击其他collecn.view项目,以便像以前那样将它们添加到字典数组中时,最初添加到字典数组中的项目获取再次添加。 这必须以某种方式阻止。 正如另一个SO用户所build议的这样的尝试,以防止这种重复… if self.arrayOfDictionary.contains(where: { (dict) -> Bool in "\(dict["id"] ?? "")" != "\(dictionary["id"] ?? "")"}) { self.arrayOfDictionary.append(dictionary) } 但是这似乎不起作用。 没有任何东西被添加到数组中,而它完全是空的。 希望有人能帮助…

如何获得一年中的月份数?

我想要一个函数,它将返回当前一个月的当前一周数组。 例如,如果当前月份是2015年8月,则会返回[32,33,34,35,36]。 如果月份是2015年2月,则会返回[6,7,8,9]。 有没有办法,我怎么能得到这个? 在苹果文档NSCalendar类有一个选项来获得本年的数量,但这不是我所需要的。

大量内存消耗:ImageIO_jpeg_Data

我有一个TableViewController显示一个用户的图像和一些文本每行的条目。 这个图像加载在“cellForRowAtIndexPath”方法中: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell : ApplicantsCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ApplicantsCell {…} let image = UIImage(named: "avatar") cell.applicantImage.image = image if let applImage = applicant.image as PFFile? { applImage.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in if error == nil { let image = UIImage(data: imageData!) […]

枚举rawvalue作为AnyClass

我知道你可以给枚举的String或Int的原始值,但有没有办法使其types像AnyClass例如 enum Name:AnyClass{ case classOne = ClassOne case classTwo = ClassTwo } ClassOne和ClassTwo是类。 我得到的错误是: 原始types“AnyClass”不能从任何文字转换 那么还有另一种方法来实现这一目标吗?

UIViewanimation跳过第一个animation

对这个抱歉很新! 一旦我运行按button“按”UIView“背景”的背景颜色立即改变为蓝色,然后animation到紫色,完全跳过animation黄色,然后到蓝色。 我做错了什么? @IBAction func Press(sender: AnyObject) { UIView.animateWithDuration(5, animations: { self.Background.backgroundColor = UIColor.yellowColor() self.Background.backgroundColor = UIColor.blueColor() self.Background.backgroundColor = UIColor.purpleColor() }, completion:{(Bool) in println("COLOR CHANGED") }) }

不能得到这个checkbox来build立?

我试图解决其他错误,所以它可能看起来有点不同,但这是我能做的最好的。 override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() Box49.setImage(#imageLiteral(resourceName: "UnCheckBox"), for: .normal) Box49.setImage(#imageLiteral(resourceName: "CheckBox"), for: .selected) Box50.setImage(#imageLiteral(resourceName: "UnCheckBox"), for: .normal) Box50.setImage(#imageLiteral(resourceName: "CheckBox"), for: .selected) Box51.setImage(#imageLiteral(resourceName: "UnCheckBox"), for: .normal) Box51.setImage(#imageLiteral(resourceName: "CheckBox"), for: .selected) } @IBAction func Box49(_ sender: UIButton) { sender.isSelected = !(sender as AnyObject).isSelected } @IBAction func Box50(_ sender: UIButton) { sender.isSelected = !(sender as AnyObject).isSelected } […]

EKEventEditViewController会冻结应用程序并在很长时间后加载

我在swift中有以下代码: var eventController = EKEventEditViewController() eventController.editViewDelegate = self var store = EKEventStore() eventController.eventStore = store var event = EKEvent(eventStore: store) event.title = viewModel.roleName event.location = viewModel.location event.startDate = viewModel.startDate event.endDate = viewModel.endDate eventController.event = event var status = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent) switch status { case .Authorized: self.setNavBarAppearanceStandard() dispatch_async(dispatch_get_main_queue(), { () -> Void in self.presentViewController(eventController, animated: true, completion: […]

滚动时隐藏导航栏

我想知道,如果它的确定通过iOS人机界面准则来devise一个UIView,使它看起来像一个导航栏。 我的问题是,我想隐藏当前的导航栏,一旦用户滚动。 我已经尝试self.navigationController?.setNavigationBarHidden(true, animated: true)和navigationController?.hidesBarsOnSwipe = true但animation看起来很奇怪,一旦导航栏被隐藏我仍然有状态栏下面约20px的空间:你可以看在我的另一个问题 所以为了让事情变得更简单,我可以在隐藏的导航栏中初始化我的视图,并设置自己的样式并添加适当的animation?

用swift 3从开始位置切换到结束位置

我有string\string示例的string "some sting with random length\233" 我想删除最后的\并获得它后面的值,所以结果将是 "some sting with random length" "233" 我试过这个代码,但它不工作 let regex = try! NSRegularExpression(pattern: "\\\s*(\\S[^,]*)$") if let match = regex.firstMatch(in: string, range: string.nsRange) { let result = string.substring(with: match.rangeAt(1)) }