我正在尝试将数字值转换为两位小数。但是当我将其转换为0.00时。数字是这个0.24612035420731018。当获得其.2f值时,它将显示0.00。我试过的代码是这样的,
let digit = FindResturantSerivce.instance.FindResModelInstance[indexPath.row].distance
let text = String(format: "%.2f", arguments: [digit])
print(text)
Run Code Online (Sandbox Code Playgroud) 我正在从图库中选择多个图像并将所有选定的图像放在一个数组中.我想在我的集合视图中显示这些图像.我有一个集合视图,在单元格中我创建了一个imageView.现在我试图将我的图像数组传递给单元格中的图像视图.但是当我点击完成按钮时,它只在集合视图单元格中显示一个图像.我已经使用断点检查我的循环循环工作正常,但它只显示一个图像.如何显示阵列中的所有图像?我的代码是这样的:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = uploadDocCollectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! UploadDocsImagesCollectionViewCell
for i in 0..<imagesArray.count{
cell.imageView.image = imagesArray[i]
}
return cell
}
Run Code Online (Sandbox Code Playgroud)