I am using two collectionviews and showing and hiding them according to conditions
initially i want to show newCollectionview with newArray images
code for collectionviews: with this code isEdit condition working perfectly.. but inatially when i upload images from picker then in cellForItemAt
else condition not calling and added images(newArray) are also not showing in newCollectionView
here numberOfItemsInSection
else return self.newArray.count
is calling and count showing but the images not showing in newCollectionView
struct ImagesModel{
public var image : String?
init(image: String?) {
self.image = image
}
}
import UIKit
class BidPlaceVC: UIViewController, UITextViewDelegate {
var oldArray = [ImagesModel]()
var newArray = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
layout.scrollDirection = .horizontal
let width = UIScreen.main.bounds.width/4.1
let height = width*1.1
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 5
layout.itemSize = CGSize(width: width, height: 100)
self.newCollectionView.collectionViewLayout = layout
self.oldCollectionnview.collectionViewLayout = layout
newCollectionView.reloadData()
oldCollectionnview.reloadData()
}
func uploadServiceCall() {
let param = ["service_request" : bserviceId!, "amount" : amountTf.text ?? "100", "no_of_hours" : "2", "description" : proposalTextView.text ?? ""] as [String : Any]
var imgData = [Data]()
for image in self.newArray {
imgData.append(image.jpegData(compressionQuality: 0.5)!)
}
APIReqeustManager.sharedInstance.uploadMultipleImagesWithParam(url: CommonUrl.place_bid, imagesData: imgData, imageKey: "files", parameters: param, vc: self, loaderNeed: true, completionHandler: {(responseData) in
DispatchQueue.main.async {
self.newCollectionView.reloadData()
}
}
}
extension BidPlaceVC : UICollectionViewDelegate,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if isEdit {
if newArray.isEmpty{
if collectionView == oldCollectionnview{
return oldArray.count
}
}
else{
if collectionView == oldCollectionnview{
return oldArray.count
}
if collectionView == newCollectionView{
return self.newArray.count
}
}
}else {
if collectionView == newCollectionView{
return self.newArray.count// is calling
}
}
return newArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if isEdit{
if newArray.isEmpty{
if collectionView == oldCollectionnview{
let cell = oldCollectionnview.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
let img = "\(CommonUrl.bidsAttachment)\( self.oldArray[indexPath.item].image ?? "")"
cell?.imgView.getImage(withUrl: img, placeHolder: #imageLiteral(resourceName: "home"), imgContentMode: .scaleAspectFill)
return cell!
}
}
else{
if collectionView == oldCollectionnview{
let cell = oldCollectionnview.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
let img = "\(CommonUrl.bidsAttachment)\( self.oldArray[indexPath.item].image ?? "")"
print("\(img)")
cell?.imgView.getImage(withUrl: img, placeHolder: #imageLiteral(resourceName: "home"), imgContentMode: .scaleAspectFill)
return cell!
}
// if i come from isEdit then its calling.. and images showing in newCollectionView
if collectionView == newCollectionView{
let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
cell?.imgView.image = self.newArray[indexPath.item]
return cell!
}
}
}
//******* here is not calling ******
else{
if collectionView == newCollectionView{
let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
print("first time \(self.newArray)")
cell?.imgView.image = self.newArray[indexPath.item]
return cell!
}
}
return UICollectionViewCell()
}
}
extension BidPlaceVC : EasyImagePickerDelegate{
func didSelect(image: UIImage?, video: URL?, fileName: String?) {
if let img = image{
self.imageProfile = img
self.newArray.append(img)
print("added images \(newArray)")
self.newCollectionView.reloadData()
}
}
}
Aucun commentaire:
Enregistrer un commentaire