草庐IT

swift-block

全部标签

ios - 基于字符串数组 (Swift) 在 UITableView 的 viewdidload 上选择单元格

如何根据核心数据数组中的匹配字符串值在UITableview中选择多个单元格?我已经保存了之前选择的行(作为字符串),但现在当我再次加载表格时,我希望所有内容都被再次选中。我找不到或想不出任何解决方案。数组:varcategory:[String]=["News","Sport","Weather","Earth","Future","Shop","TV","Radio","Food","Music","Travel","Local","Nature","Venue","Money"]我试图找出selectRowAtIndexPath但我没有在Swift中看到它。这是我如何从CoreD

ios - prepareForSegue UICollectionView 不工作( swift )

我尝试使用UICollectionView(将图像从MasterView显示到DeatilView)来推送segue,但没有用。Xcode也没有显示任何错误信息。我的代码有什么问题。我需要一些建议。overridefuncprepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?){ifsegue.identifier=="showDetail"{ifletindexPath=self.collectionView?.indexPathForCell(senderas!UICollectionViewCell){letdetail

ios - 在其他 swift 文件中调用时,AVAudioPlayer 不会播放声音

我有两个swift文件——我的ViewController:UIViewController和AudioPlayer:AVAudioPlayer。我的AudioPlayer文件有这个功能funcseaGullSound(){vartmp=AVAudioPlayer()varseaGullSound=NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("Gulls",ofType:"mp3")!)AVAudioSession.sharedInstance().setCategory(AVAudioSessionCateg

swift - 我的协议(protocol)定义在另一个 Swift 文件中不可见

我有两个文件:DBStartViewController.swift和DBFindViewController.swift当我定义我的协议(protocol)时:protocolDBViewAnimationTransitioning{varviewForAnimation:UIView?{getset}}在DBStartViewController.swift中,它在我的DBFindViewController.swift中不可见。我得到一个错误:UseofundeclaredtypeDBViewAnimationTransitioning.但是当我将声明移动到DBFindViewC

sql - 在 Swift 中,使用带有撇号的 SQL 查询

我有一个用户破坏了我原本可以正常工作的代码,我认为这是因为他的名字有一个撇号。我尝试使用双撇号和反斜杠转义它,但我不断收到fatalerror:unwhileunwrappinganOptionalvalue时意外发现nil。letquerySQL="SELECTnamefrommember_dataORDERBYRANDOM()LIMIT1"rightAnswer=memberDatabase!.executeQuery(querySQL,withArgumentsInArray:nil)rightAnswer!.next()correctName=rightAnswer!.stri

ios - NSPredicate 在 swift 中检查对象类的种类

我有以下核心数据模型:现在我想获取所有类型为CDOnlineContact和CDOfflineContact的对象。所以我有以下fetchedController:letfetchRequest=NSFetchRequest(entityName:"CDContact")fetchRequest.predicate=NSPredicate(format:"???%@",CDOnlineContact,CDOfflineContact)//我在objective-c中找到了一些解决方案...NSPredicate*predicate=[NSPredicatepredicateWithFo

ios - Swift 中的核心数据通知

我正在尝试从CoreData通知中的userInfo获取更新的对象。我在Objc中运行良好,但在Swift中却很难。我已经尝试通过几种方式获取数据,但这是我当前的实现,它总是返回nil:noti.userInfo?[NSUpdatedObjectsKey]如何获取数据?这是有效的Objc代码:NSArray*updatedObjects=[[noti.userInfoobjectForKey:NSUpdatedObjectsKey]allObjects]; 最佳答案 注册通知。不要忘记在对象被取消时删除。NotificationCe

ios - Swift - 通过委托(delegate)将 UIImage 传递给 UIImageView

我没有想法,我不知道如何解决这个问题。任何帮助将不胜感激。我有以下情况:MainViewController指向嵌入在NavController中的CollectionViewCollectionView指向一个DetailViewControllerDetailViewController显示在CollectionView中选择的完整图片,并有一个将此图像传递给MainViewController的按钮。为此使用协议(protocol)和委托(delegate)此图像现在应该显示在MainViewController的UIImageView中委托(delegate)工作。我的Main

swift - GKAgentDelegate 的协议(protocol)方法在 Swift 中不对吗?

在GameplayKit中,我想遵循协议(protocol)GKAgentDelegate,因此使用委托(delegate)方法funcagentDidUpdate(agent:GKAgent)。问题是,在这个方法中,参数agent被声明为GKAgent,而不是GKAgent2D,所以我无法访问agent.position,因为position属性在GKAgent2D中,而不是GKAgent...但是在Objective-CAPI中,agent被声明为GKAgent2D。请帮忙。 最佳答案 由于GKAgent2D是GKAgent的子

swift - 将字典中的整数相加

希望将字典中的整数相加。例如:vardictionary=["one":1,"two":2,"three":3,"four":4,"five":5]我想得到1+2+3+4+5=15的总和我知道它可能需要一个像这样的循环for(n,i)indictionary{*somemathfunction*}任何帮助将不胜感激,也许我只是在想这个? 最佳答案 您可以使用reduce:combine:来获得总和。在Swift2.0中,reduce:Combine:被添加到SequenceType的协议(protocol)扩展中。因此,它适用于所有