Tag: swift2

故障 – 核心数据只能在使用UITableView时访问一次对象

好吧,这是一个奇怪的错误,我无法弄清楚。 我从核心数据实体获取费用。 然后我把这些结果sorting。 我使用这个sorting的结构来获取正确的部分和tableView中的行正确的数据。 此代码全部正常工作,并且TableForcts中的单元格在cellForRowAtIndexPath中正确填充。 但是,当一个单元格退出tableView(= queued),然后又被加载回来(= dequeued)时,我不能再访问这个开销和它的关系了…… 让我进一步解释一下:这里的核心数据结构 extension Category { @NSManaged var name: String? @NSManaged var catHasExpenses: NSOrderedSet? } extension Expenses { @NSManaged var amount: NSNumber @NSManaged var name: String? @NSManaged var date: NSDate @NSManaged var expenseHasCat: Category } 我获取数据并对其进行分类。 此代码仍然正常工作,所以继续前进。 当它对数据结构进行sorting时 var expensesDictionary = ([(NSDate, Expenses)])() //Array of tuples 然后,当单元格加载我想访问费用的HasCat关系。 第一次加载表格时,一切正常。 func […]

如何快速设置每周本地通知

我的代码有问题。 我想在xcode7中设置一个本地通知,我正在开发一个日历,你可以把你的大学的课程,事情是,我从json数据库得到的时间表,我想通知15分钟之前的课程开始,但我不知道为什么我的代码不工作。 这是我想在每个星期一13:40重复通知的一个例子。 我只能设置date和时间吗? 还是应该指定月份和年份呢? var dateComp:NSDateComponents = NSDateComponents() dateComp.day = 01; dateComp.hour = 13; dateComp.minute = 40; dateComp.timeZone = NSTimeZone.systemTimeZone() var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! var date:NSDate = calender.dateFromComponents(dateComp)! let notification = UILocalNotification() notification.fireDate = date notification.alertBody = "Swipe to unlock" notification.alertAction = "You've got a class soon!" notification.soundName = UILocalNotificationDefaultSoundName notification.userInfo = ["CustomField1": […]

当滚动浏览其中有一个CollectionView的TableView时崩溃

我有这个问题( UICollectionView里面的UITableViewCell – AutoLayout ) 并尝试了几个解决scheme,这是在互联网上可用我带着这个@Pablo Romeu的答案我试着他的解决scheme,现在我有一个TableView与其中的collectionView单元格(它可以dynamic地改变其大小的内容),但是当滚动浏览我的表查看它碰到这个错误: 2016-06-13 22:05:51.546 WishMeluck[3507:425240] the behavior of the UICollectionViewFlowLayout is not defined because: 2016-06-13 22:05:51.546 WishMeluck[3507:425240] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values. 2016-06-13 22:05:51.546 WishMeluck[3507:425240] Please check […]

取消并重新安排本地通知(Swift)

我试图以1天(24小时)的时间间隔显示本地通知,并且其工作正常,但是现在我想取消特定date的通知。 我试过(今天)这个,但似乎没有工作。 我的通知仍然出现,这是我已经做了取消通知: let appNotification = appDelegate!.notification UIApplication.sharedApplication().cancelLocalNotification(appNotification) 这是如何安排在appDelegate的通知: //scheduling notification dateComp.year = 2015; dateComp.month = 01; dateComp.day = 20; dateComp.hour = 21; dateComp.minute = 05; dateComp.timeZone = NSTimeZone.systemTimeZone() notification.category = "FIRST_CATEGORY" notification.alertBody = "my daily notiification ?" notification.soundName = UILocalNotificationDefaultSoundName notification.fireDate = finalFireDate notification.repeatInterval = NSCalendarUnit.Day let dateNow = NSDate() let noticalendar = NSCalendar.currentCalendar() […]

终止应用程序由于未捕获的exception“NSRangeException”,原因:'*** –

我试图运行iPhone 6上的应用程序,我得到这个错误。 在loginFacebook之后出现错误。 通常,它在模拟器上正常工作。 我找不到为什么会出现这个错误。 错误: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray' *** First throw call stack: (0x181dcae38 0x18142ff80 0x181d41a6c 0x100418620 0x100417aa0 0x10042dbac 0x10006a3a0 0x10006aa0c 0x186f14b40 0x186f14744 0x1872ba9fc 0x1872774f4 0x187273f04 0x1871c6fd8 0x1871d4990 0x186f064a4 0x181d807b0 0x181d7e554 0x181d7e984 0x181ca8d10 0x183590088 0x186f7df70 0x10008810c 0x1818468b8) libc++abi.dylib: […]

确定coreData属性的types

我写了一个库,允许开发人员在coreData上应用SQL代码,如下所示: let manager = coreSQL() manager.prepare("INSERT INTO Entity (name, age) VALUES (?,?)") manager.execute(["Chuck Norris" , "76"]) 插入coreData我使用这个 let context:NSManagedObjectContext = appDel.managedObjectContext let newRow = NSEntityDescription.insertNewObjectForEntityForName(tableName, inManagedObjectContext: context) if (columnsArray.count == values.count){ for i in 0 ..< columnsArray.count{ newRow.setValue(values[i], forKey: columnsArray[i]) } do {try context.save()} catch _ {} } columnsArray = [“名称”,“年龄”] 值= [“查克·诺里斯”,“76”] 问题是,在我的coreData对象的年龄属性是整型的types,你可能会注意到查克·诺里斯的年龄是string,所以当我尝试执行我的应用程序时,我得到一个错误: 终止由于未捕获的exception'NSInvalidArgumentException'的应用程序,原因:'不可接受的属性types的值:属性=“年龄”; […]

它如何才能迅速closures它的类的引用属性运行?

我有以下2个控制器列出如下。 我正在使用委托来尝试创build一个progressWindow,它将运行代码并很好地打印它,但代码是任意的。 闭包由符合协议的类定义(在我的情况下是SyncViewController), 但是我想从SyncViewControllers codeToRun {}闭包中更改progressWindowViewController的UI。 我该怎么做呢? SyncViewController.swift import UIKit class SyncViewController: UIViewController, progressWindowDelegate { var codeToRun = { //(self as! ProgressWindowViewController).theTextView.text = "changed the text" print("code to run") } var codeToCancel = {print("code to cancel")} var titleToGive = "Starting Sync…" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. […]

滚动后,UITcrollView中的UITextFied未启用

我在ViewController中添加了UIScrollView ,并在该UIScrollView下添加了UIView 我在该UIView添加了10个UITextFields ,滚动工作正常 在Simulator / iPhone中运行应用程序时,前6个UITextFields在屏幕上显示而不滚动,剩余的4个UITextFields不工作[对触摸没有响应],这将在滚动后显示 请任何人指导我解决这个问题? 谢谢 更新:我在ViewController中使用它 override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 1070); } ViewControllerStructure如下

iOS外围设备服务发现后仍为空

我想使用蓝牙我有这样的事情: func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { Connected = true TableView.reloadData() Activityview.stopAnimating() TabBar.topItem!.rightBarButtonItem = UIBarButtonItem(title: "Suivant", style: UIBarButtonItemStyle.Done, target: nil, action: #selector(Connexion.next)) CM.stopScan() Scanning = false Refresh_Button.setTitle("Deconnecté", forState: UIControlState.Normal) let AlertMessage = UIAlertController(title: "Connecté", message: "Le module est bien connecté", preferredStyle: .Alert) let ActionAlert = UIAlertAction(title: "Ok", style: .Default) { (action) in } AlertMessage.addAction(ActionAlert) […]

正在发送到新的视图控制器的数据是零,展开一个可选值

当我尝试传递我的Event类的细节到另一个控制器时,我得到一个错误,说: "fatal error: unexpectedly found nil while unwrapping an Optional value" 。 这是我的视图控制器发送信息: var eventDetailscontrollers: EventDetailsController! func showDetailView(event: Events){ let mainStoryBoarrd: UIStoryboard = UIStoryboard(name:"Main", bundle:nil) let detailsViewController: UIViewController = mainStoryBoarrd.instantiateViewControllerWithIdentifier("eventDetailsID") eventDetailscontrollers?.event = event //this sends all info as nil eventDetailscontrollers.event = event //this causes error print(event.name) // this prints event name fine self.presentViewController(detailsViewController, animated: true, […]