0

I'm trying to use a gridview inside a tableView. But i have a problem when i load images async.

I have N Table's cell with different number of collection's cells. how can i develop it?

I'm using this, but i have some problems when i reload and load different number of items...

https://github.com/TheDLu/CollectionView-in-TableView/blob/master/CollectionView%20in%20TableView/MainTableViewController.swift

i load the data -> tablereload -> collectionviewreload ---------^ Give more info

Suggestions of best practice?

Thanks!

myfunction:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    if (columna>0){
       // println("adasdasd \(columna)")
        return columna! as Int}
    else{
    return 0
    }}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {



    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("GridFotosCell", forIndexPath: indexPath) as GridFotosCell



    // Add a check to make sure this exist

    // Check our image cache for the existing key. This is just a dictionary of UIImages
    //var image: UIImage? = self.imageCache.valueForKey(urlString) as? UIImage
    if( AlbumArray[fila!].albumfotoslinks?.count > indexPath.row) {
    if( AlbumArray[fila!].albumfotoslow?[indexPath.row] == nil ) {
        // If the image does not exist, we need to download it

        var link = AlbumArray[fila!]
        var finalink = link.albumfotoslinks?[indexPath.row]
        finalink = finalink!.stringByReplacingOccurrencesOfString(" ", withString: "%20", options: NSStringCompareOptions.LiteralSearch, range: nil)
        finalink = finalink!.stringByReplacingOccurrencesOfString("+", withString: "%2B", options: NSStringCompareOptions.LiteralSearch, range: nil)
        var urlfinal = NSURL(string: "x")
        //println(urlfinal!)

        // Download an NSData representation of the image at the URL
        let request: NSURLRequest = NSURLRequest(URL: urlfinal!)
        NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in

            if error == nil {

                imageneslow.append(UIImage(data: data)! as UIImage) << i need 2 dimension?

                cell.GridFoto.image = imageneslow.last

                /*
                dispatch_async(dispatch_get_main_queue(), {
                    if let cellToUpdate = self.TableAlbum.cellForRowAtIndexPath(indexPath) {
                        cellToUpdate.imageView?.image = (UIImage(data: data)! as UIImage)

                    }
                })*/
                // Store the image in to our cache
             //  AlbumArray[fila!].albumfotoslow! = imagenes

            }
            else {
                println("Error: \(error.localizedDescription)")
            }
        })

    }
    else {
        //dispatch_async(dispatch_get_main_queue(), {
          //  if let cellToUpdate = TableAlbum.cellForRowAtIndexPath(indexPath) {
            //    cellToUpdate.imageView?.image = image
            //}
         cell.GridFoto.image = imageneslow.last
        }

    }
   // println( AlbumArray[fila!].albumfotoslow?[indexPath.row])
    //println(cell.GridFoto.image?.debugDescription)
    //println("reloadgrid")
    NSLog("return de celda")
            NSLog(String.convertFromStringInterpolationSegment(fila))

    return cell
Pedro Manfredi
  • 3,768
  • 5
  • 19
  • 24
  • 1.set a "content setup" function in your table cell that will manage the cell content loading. 2. set the cell as the delegate+data source of it's specific collection. 3 . in your function (1) reload the collection * make sure you manage your scrolls properly and use lazy loading for the images – Nevgauker Mar 22 '15 at 09:56
  • Can you explain me pls how should look like the content setup... ? thxx – Pedro Manfredi Apr 17 '15 at 11:10
  • check this link : https://stackoverflow.com/a/45618501/3400991 – Shobhakar Tiwari Aug 10 '17 at 17:00

0 Answers0