let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhoneDetailsCC", for: indexPath) as? PhoneDetailsCC
let imageUrl = phoneModel?.imageUrl[indexPath.row]
cell?.phoneDetailsImage.sd_setImage(with: URL(string: imageUrl!))
return cell!
}
i am casting here cell image phoneDetailsImage and i use here sd_setimage to download inside array to come it other tableview each row also every cell to use model
let imageUrl = phoneModel?.imageUrl[indexPath.row]
this is and string array [string]
and sdwebimage show inside url to convert image but i have another problem to it
i am create an pdf in this every cell to use pdfkit beforo i used just 1 image and i prepared and send it other vc but i dont know how i send array of image to other vc i will share other code below
import FirebaseStorage
import FirebaseFirestore
import SDWebImage
import ProgressHUD
import PDFKit
class PhoneListViewController: UITableViewController {
@IBOutlet weak var phoneModelText: UITextView!
@IBOutlet weak var imeiAdressText: UITextView!
@IBOutlet weak var userNameText: UITextView!
@IBOutlet weak var idText: UITextView!
@IBOutlet weak var phoneNumberText: UITextView!
@IBOutlet weak var detailsText: UITextView!
@IBOutlet weak var dateText: UITextView!
@IBOutlet weak var priceText: UITextView!
@IBOutlet weak var adressText: UITextView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var imageCollectionView: UICollectionView!
public var documentData: Data?
var phoneModel : PhoneModel?
override func viewDidLoad() {
super.viewDidLoad()
imageCollectionView.delegate = self
imageCollectionView.dataSource = self
view.backgroundColor? = UIColor.systemGray3
tableView.backgroundView = UIImageView(image: UIImage(named: "SplashScreen.jpeg"))
tableView.backgroundView?.alpha = 0.2
phoneModelText.text = phoneModel?.phoneModelText
imeiAdressText.text = phoneModel?.imeiAdressText
userNameText.text = phoneModel?.userNameText
idText.text = phoneModel?.idText
phoneNumberText.text = phoneModel?.phoneNumberText
detailsText.text = phoneModel?.detailsText
dateText.text = phoneModel?.dateText
priceText.text = phoneModel?.priceText
adressText.text = phoneModel?.adressText
imageCollectionView.register(UINib(nibName:"PhoneDetailsCC", bundle: Bundle.main), forCellWithReuseIdentifier: "PhoneDetailsCC")
}
@IBAction func printAction(_ sender: Any) {
let pdfPreview = PDFView()
if let data = documentData {
pdfPreview.document = PDFDocument(data: data)
pdfPreview.autoScales = true
}
view.addSubview(pdfPreview)
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if
let _ = phoneModelText.text,
let _ = userNameText.text,
let _ = imageView.image, // this is i used before only 1 image and this is worked for me
let _ = adressText.text {
return true
}
let alert = UIAlertController(title: "Please Wait, Try again", message: "You Need to be wait downloading all image", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
return false
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == K.pdfSegue {
guard let vc = segue.destination as? PDFViewController else { return }
if let phoneM = phoneModelText.text,
let imeiA = imeiAdressText.text,
let nameS = userNameText.text,
let idN = idText.text,
let phoneN = phoneNumberText.text,
let adressT = adressText.text,
let detailS = detailsText.text,
let priceC = priceText.text,
let dateT = dateText.text,
let imageV = imageView.image
{
let pdfCreate = PDFCreate(phoneModel: phoneM, imeiAdress: imeiA, nameSurname: nameS, id: idN, phoneNumber: phoneN, adress: adressT, details: detailS, price: priceC, date: dateT, image: imageV)
vc.documentData = pdfCreate.createPdf()
} //this model use to create of the inside of pdf other text is passing well
}
}
}
extension PhoneListViewController: UICollectionViewDelegate,UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return phoneModel?.imageUrl.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhoneDetailsCC", for: indexPath) as? PhoneDetailsCC
let imageUrl = phoneModel?.imageUrl[indexPath.row]
cell?.phoneDetailsImage.sd_setImage(with: URL(string: imageUrl!))
return cell!
}
}
how i send it array of images to use sdwebimage inside of collection view data to other vc Thank you for answers...
It is hard to understand what you want to do.
.
how i send it array of images
Where is this array defined ? What is its name ?
For example, if it is defined in PhoneListViewController as
var images: [UIImage]
What is the var that will receive the array in the destination controller (PDFViewController ?)
if it is defined as:
var receivedImages: [UIImage]?
Then, in prepare you have to write:
vc.receivedImages = self.images
Note: the forced unwrap at the end on cell! is dangerous.
You should better:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhoneDetailsCC", for: indexPath) as? PhoneDetailsCC else { return UICollectionViewCell() }
let imageUrl = phoneModel?.imageUrl[indexPath.row]
cell.phoneDetailsImage.sd_setImage(with: URL(string: imageUrl!))
return cell
}