我一直在故障排除显示UIImageView,我不知道它哪里不让我. MainViewController FullViewController ImageTableViewCell UIImage:0x600001e641b0匿名{1080 1080}> 所有的间距标签似乎都起作用了. 有没有显示UIImageview的选项? 谢谢!

我一直在故障排除显示UIImageView,我不知道它哪里不让我。

MainViewController

class MainViewController: UIViewController {
    
    @IBOutlet weak var mainTableView: UITableView!
    
    var imageArray : [PhotoModel] = []
    var images = [UIImage]()
    var imageRatio = [CGFloat]()
    var currentIndex = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.hidesBackButton = true
        
        let dispatchGroup = DispatchGroup()
        dispatchGroup.enter()
        
        PhotoManager().fetchPhotos(query: "") { (data, error) in
            self.imageArray = data
            
            for d in data {
                let url = URL(string: d.url)
                let imageURL = try? Data(contentsOf: url!)
                let image = UIImage(data: imageURL!)
                self.images.append(image!)
            }
            
            for d in data {
                let ratio = CGFloat(d.width / d.height)
                self.imageRatio.append(ratio)
            }
            dispatchGroup.leave()
        }
        dispatchGroup.notify(queue: .main){
            print("reloadingData")
            self.mainTableView.reloadData()
        }
    }
        
}
extension MainViewController: UITableViewDataSource, UITableViewDelegate {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return imageArray.count
    }
      
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      
        let cell = tableView.dequeueReusableCell(withIdentifier: "imageCell", for: indexPath) as! ImageTableViewCell
        DispatchQueue.main.async {
            cell.randomImageView?.image = self.images[indexPath.row]
            cell.nameLabel?.text = self.imageArray[indexPath.row].username
        }
        return cell
        
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return tableView.frame.width/imageRatio[indexPath.row]
    }
    
    //tableView delegate
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        currentIndex = indexPath.row
        print(imageArray[currentIndex].name)
        performSegue(withIdentifier: "full", sender: self)
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let destination = segue.destination as! FullViewController
        destination.images = self.images
        destination.currentIndex = self.currentIndex
    }
}

FullViewController

class FullViewController: UIViewController {
    @IBOutlet weak var fullCollectionView: UICollectionView!
    
    var images = [UIImage]()
    var currentIndex = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        fullCollectionView.isPagingEnabled = true
    }
    
    override func viewWillAppear(_ animated: Bool) {
        fullCollectionView.selectItem(at: IndexPath(item: currentIndex, section: 0), animated: true, scrollPosition: .centeredHorizontally)
    }
}
extension FullViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return images.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! FullImageCollectionViewCell
        cell.fullScreenImages.image = images[indexPath.row]
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
}

ImageTableViewCell

class ImageTableViewCell: UITableViewCell {
 
    @IBOutlet weak var randomImageView: UIImageView?
    @IBOutlet weak var nameLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }
}

UIImage:0x600001e641b0匿名{1080 1080}>

所有的间距标签似乎都起作用了。

有没有显示UIImageview的选项?

谢谢!

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码