heyy coders i am stucking in this problem
var val1 : String? = ""
var val2 : String? = ""
var val3 : String? = ""
var val4 : String? = ""
let img = phoneImage[indexPath.row].imageUrl.enumerated().forEach { index,string in
if index == 0 {
val1?.append(string)
print(string)
} else if index == 1 {
val2?.append(string)
} else if index == 2 {
val3?.append(string)
}else if index == 3 {
val4?.append(string)
}
}
let imagess = [LightboxImage(imageURL: URL(string: val1!)!),
LightboxImage(imageURL: URL(string: val2!)!),
LightboxImage(imageURL: URL(string: val3!)!),
LightboxImage(imageURL: URL(string: val4!)!) ]
let me explain what is problem i need some idea to append other array downbelow code
let imagess = [LightboxImage(imageURL: URL(string:val1!)!),
LightboxImage(imageURL: URL(string:val2!)!),
LightboxImage(imageURL: URL(string:val3!)!),
LightboxImage(imageURL: URL(string:val4!)!) ]
this is my final array every calling time is need update but everytime comeing this type
LightboxImage(imageURL: URL(string: val1!)!)
how to i figure it
how i append LightboxImage(imageURL: URL(string: val1!)!) to array
every time if 3. and 4. value nil app is crash it
Thank you for help.
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...