I am getting data from json web services but unable to display it on my ui

后端 未结 1 1161
夕颜
夕颜 2021-01-28 05:53

here I am having problem that I am able to get the data from json web services but unable to display on my ui in the program I mentioned where I am getting error and what it is

相关标签:
1条回答
  • 2021-01-28 06:30

    what you are using to display image in func swiped(gesture: UIGestureRecognizer) method execution is as below

    imageView.image = UIImage(named: imageArray[pageIndex])
    

    but your image is comping from the server so you just need to display all images of your product is as you displayed first in OperationQueue.main.addOperation so in place of displaying image using UIImage(named: imageArray[pageIndex]) you need to convert it to data and display it to imageview and your modified func swiped(gesture: UIGestureRecognizer) may look like as below

    func swiped(gesture: UIGestureRecognizer) {
            if let swipeGesture = gesture as? UISwipeGestureRecognizer {
                switch swipeGesture.direction {
                case UISwipeGestureRecognizerDirection.right :
                    if pageIndex == 0 {
    
                    }else{
                        pageIndex -= 1
                    }
                    let imgURL = NSURL(string:self.imageArray[pageIndex])
                    let data = NSData(contentsOf: (imgURL as URL?)!)
                    self.imageView.image = UIImage(data: data! as Data)
    
                case UISwipeGestureRecognizerDirection.left:
                    if pageIndex >= imageArray.count-1{
    
                    }else{
                        pageIndex += 1
                    }
                    let imgURL = NSURL(string:self.imageArray[pageIndex])
                    let data = NSData(contentsOf: (imgURL as URL?)!)
                    self.imageView.image = UIImage(data: data! as Data)
                default:
                    break
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题