草庐IT

index_length

全部标签

swift - UICollectionView 接收到具有不存在的索引路径的单元格的布局属性 : <NSIndexPath: 0x79fe0f20> {length = 2, 路径 = 0 - 4}

当我第一次加载我的UICollectionView时没有任何问题,我使用自定义布局和serachbar,当我搜索一些文本时它崩溃抛出异常,即具有不存在的索引路径的单元格,我使用像下一个代码一样的搜索栏:importUIKitimportAVFoundationclassCategoryViewController:UIViewController,UICollectionViewDataSource,UICollectionViewDelegate,UISearchBarDelegate{varListArray:JSON!=[]varSelectedIds:[Int]=[]varSe

ios - swift fatal error : array index out of range

我正在制作一个待办事项列表应用程序,但是当我尝试从我的列表中删除某些内容时,xcode给我一个错误,提示“fatalerror:数组索引超出范围”。有人可以告诉我我的数组做错了什么导致发生这种情况吗?importUIKitclassSecondViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfrom

ios - 如何为 UITableView 中的 Index Bar 部分设置透明背景?

如何在UITableView中为sectionsindexbar设置透明背景?我试过:tableView.sectionIndexBackgroundColor=.clearColor()但是栏的背景是浅灰色编辑我尝试更改tableview的背景颜色,但它似乎没有影响。tableView.backgroundView=UIView.init()tableView.backgroundColor=.blackColor()//tried.clearColor()too.EDIT2tableView.sectionIndexBackgroundColor=UIColor(white:CGF

ios - 'Int' 与 'String.Index' 不同

作为练习,我正在使用Swift重写我的一个应用。在Objective-C中,我有以下代码行:NSRangeextendedRange=NSUnionRange(range,[[self.backingStorestring]lineRangeForRange:NSMakeRange(NSMaxRange(range),0)]);在swift中它看起来像这样:letstr=backingStore.stringletextendedRange:NSRange=NSUnionRange(range,str.lineRangeForRange(NSMakeRange(NSMaxRange(r

swift - AVAudioFile.length 为 0 即使文件存在

我正在创建一个用于将声音写入声音文件的AVAudioFile。如果文件已经存在,我想将framePosition移动到文件末尾,以便在末尾继续写入,而不是替换现有文件。我做了一些测试,试图从文件中读取缓冲区到一个新文件中,使用不同的URL,这样它就不会覆盖原始文件。当我尝试将缓冲区读入新文件时发生崩溃:letaudioFile=tryAVAudioFile(forReading:[URLtoexisting.caffile])letaudioFrameCount=AVAudioFrameCount(UInt32(audioFile.length))letaudioBuffer=AVAu

ios - 在哪些函数中,如何在LiquidFloatingActionButton 的index cell 中添加action?

我使用以下代码在LiduidFloatingActionButton中创建了两个按钮单元格。privatefunccreateFloatingButtons(){cells.append(createButtonCell("firstCell"))cells.append(createButtonCell("secondCell"))letfloatingFrame=CGRect(x:self.view.frame.width-56-16,y:self.view.frame.height-56-36,width:56,height:56)letfloatingButton=create

swift - 从任何 UTF-16 偏移量中,找到位于字符边界上的相应 String.Index

我的目标:给定String中的任意UTF-16位置,找到代表的相应String.Index字符(即扩展字素簇)指定的UTF-16代码单元是其中的一部分。示例:(IputthecodeinaGistforeasycopyingandpasting.)这是我的测试字符串:letstr="??‍?"(注意:要将字符串视为单个字符,您需要在能够处理Unicode9中引入的具有肤色的新职业表情符号的相当新的操作系统/浏览器组合上阅读此内容。)它是由四个Unicode标量或7个UTF-16代码单元组成的单个字符(字素簇):print(str.unicodeScalars.map{"0x\(Stri

ios - 错误 : UICollectionView received layout attributes for a cell with an index path that does not exist in Swift

我“https://www.raywenderlich.com/392-uicollectionview-custom-layout-tutorial-pinterest”创建自定义UICollectionView。(调整单元格高度)如果我向上滚动,cell会继续添加,从上往下滚动刷新。当您运行您的应用程序并最初生长Cells时没有问题。但是,刷新或重新排序单元格数量时总是出错。错误:***Assertionfailurein-[UICollectionViewDatavalidateLayoutInRect:],/BuildRoot/Library/Caches/com.apple.

ios - 适用于 iOS 的 Google 登录 : error "Cannot subscript a value of type ' [String : AnyObject ]' with an index of type ' String'"

对于options[UIApplicationOpenURLOptionsSourceApplicationKey],“无法使用String类型的索引为类型[String,AnyObject]的值下标”。Swift2、iOS9.x、GoogleSignin使用CocoaPods安装。有什么提示吗?funcapplication(app:UIApplication,openURLurl:NSURL,options:[String:AnyObject])->Bool{returnGIDSignIn.sharedInstance().handleURL(url,sourceApplicati

ios - 没有 "Index out of Range"swift 的实时重新加载 UITableview

我试图每秒重新加载我的表格View。我现在拥有的是重新加载tableview对象,但由于我在重新加载之前清除了Order数组,它因索引超出范围而崩溃。这是我当前的代码varorders=[Order]()overridefuncviewDidLoad(){super.viewDidLoad()//tablestufftableview.dataSource=selftableview.delegate=self//updateordersvartimer=Timer.scheduledTimer(timeInterval:4,target:self,selector:"GetOrder