Rectangle 27 1

Write in ViewDidLoad Method

    for (int i=0; i<[imageURLArray count]; i++)
        {
             //Declare Globally
            IMGArray1=[[NSMutableArray alloc] init];

            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[imageURLArray objectAtIndex:i]]];
            NSOperationQueue *urlQue = [[NSOperationQueue alloc] init];
            [NSURLConnection sendAsynchronousRequest:urlRequest queue:urlQue completionHandler:^(NSURLResponse *response,
                                                                                                 NSData *MoblieDatadata, NSError *error)
             {
                 if ([MoblieDatadata length] >0 && error == nil)
                 {
                     UIImage *image = [[UIImage alloc]initWithData:MoblieDatadata];
                     [IMGArray1 addObject:image];

                 }
                 else if ([MoblieDatadata length] == 0 && error == nil)
                 {

                     NSLog(@"Nothing was downloaded.");



                 }
                 else if (error != nil)
                 {
                     NSLog(@"Error happened = %@", error);
                     dispatch_async(dispatch_get_main_queue(), ^{


                     });
                 }
             }];


    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                     cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        examplemycell *myCell = [collectionView
                                        dequeueReusableCellWithReuseIdentifier:@"cell"
                                        forIndexPath:indexPath];

        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        myCell.imageView.image = image;

        return myCell;
    }
    #pragma mark -
    #pragma mark UICollectionViewFlowLayoutDelegate

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        return image.size;
    }

//For setting spacing between collectionview cells
//use the delegate method like

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section  
  {
    return 10; // This is the minimum inter item spacing, can be more
  }

And Use this for verticle line spacing between cells

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

you have tried this because it is not working giving me error NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0xa781820

Well i've not used this, please give me time.Or you can take idea from this :)

i have said in question that i have tried this and it is not working

ios - UICollectionview set cell height based on image height - Stack O...

ios iphone uicollectionview
Rectangle 27 1

Example 1: Expand only one cell at a time

var section:Int?
var preSection:Int?
var expand:Bool = false


extension ViewController: UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 13
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CustomCell

        cell.textLabel.text = "\(indexPath.item)"
        cell.backgroundColor = UIColor.orange

        return cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        if (self.section != nil) {
            self.preSection = self.section
        }

        self.section = indexPath.row

        if self.preSection == self.section {
            self.preSection = nil
            self.section = nil
        }else if (self.preSection != nil) {
            self.expand = false
        }
        self.expand = !self.expand
        self.collectionView.reloadItems(at: collectionView.indexPathsForSelectedItems!)

    }

}


// MARK: - UICollectionViewDelegateFlowLayout
extension ViewController: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        if self.expand, let row = self.section, row == indexPath.row {
            return CGSize(width: self.view.bounds.width - 20, height: 300)
        }else{
            return CGSize(width: self.view.bounds.width - 20, height: 120.0)
        }

    }
}
import UIKit

class ViewController: UIViewController {


    // MARK: - Properties
    fileprivate var collectionView: UICollectionView!
    var expandSection = [Bool]()
    var items = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.items = ["A","B","C","D","E","F","G","H","J","K"]
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)

        collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.register(CustomCell.self, forCellWithReuseIdentifier: "Cell")
        collectionView.backgroundColor = UIColor.white
        self.expandSection = [Bool](repeating: false, count: self.items.count)

        self.view.addSubview(collectionView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension ViewController: UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.items.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CustomCell

        cell.textLabel.text = self.items[indexPath.row]
        cell.backgroundColor = UIColor.orange

        return cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        self.expandSection[indexPath.row] = !self.expandSection[indexPath.row]
        self.collectionView.reloadItems(at: collectionView.indexPathsForSelectedItems!)
    }

}


// MARK: - UICollectionViewDelegateFlowLayout
extension ViewController: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        if self.expandSection[indexPath.row] {
            return CGSize(width: self.view.bounds.width - 20, height: 300)
        }else{
            return CGSize(width: self.view.bounds.width - 20, height: 120.0)
        }
    }
}

ios - How to expand multiple UICollectionViewCells on tap - Stack Over...

ios iphone swift uicollectionview uicollectionviewcell
Rectangle 27 0

You don't use the concept of row in a Collection View. You need to use this method from NSIndexPath:

+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;

Notice that the row property of a NSIndexPath is declared on UITableView.h, while the item property is declared on the UICollectionView.h

ios - UICollectionView cellForItemAtIndexPath indexPath row is nil - S...

ios cocoa-touch uicollectionview nsindexpath
Rectangle 27 0

You don't use the concept of row in a Collection View. You need to use this method from NSIndexPath:

+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;

Notice that the row property of a NSIndexPath is declared on UITableView.h, while the item property is declared on the UICollectionView.h

ios - UICollectionView cellForItemAtIndexPath indexPath row is nil - S...

ios cocoa-touch uicollectionview nsindexpath
Rectangle 27 0

Write in ViewDidLoad Method

    for (int i=0; i<[imageURLArray count]; i++)
        {
             //Declare Globally
            IMGArray1=[[NSMutableArray alloc] init];

            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[imageURLArray objectAtIndex:i]]];
            NSOperationQueue *urlQue = [[NSOperationQueue alloc] init];
            [NSURLConnection sendAsynchronousRequest:urlRequest queue:urlQue completionHandler:^(NSURLResponse *response,
                                                                                                 NSData *MoblieDatadata, NSError *error)
             {
                 if ([MoblieDatadata length] >0 && error == nil)
                 {
                     UIImage *image = [[UIImage alloc]initWithData:MoblieDatadata];
                     [IMGArray1 addObject:image];

                 }
                 else if ([MoblieDatadata length] == 0 && error == nil)
                 {

                     NSLog(@"Nothing was downloaded.");



                 }
                 else if (error != nil)
                 {
                     NSLog(@"Error happened = %@", error);
                     dispatch_async(dispatch_get_main_queue(), ^{


                     });
                 }
             }];


    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                     cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        examplemycell *myCell = [collectionView
                                        dequeueReusableCellWithReuseIdentifier:@"cell"
                                        forIndexPath:indexPath];

        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        myCell.imageView.image = image;

        return myCell;
    }
    #pragma mark -
    #pragma mark UICollectionViewFlowLayoutDelegate

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        return image.size;
    }

//For setting spacing between collectionview cells
//use the delegate method like

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section  
  {
    return 10; // This is the minimum inter item spacing, can be more
  }

And Use this for verticle line spacing between cells

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

you have tried this because it is not working giving me error NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0xa781820

Well i've not used this, please give me time.Or you can take idea from this :)

i have said in question that i have tried this and it is not working

ios - UICollectionview set cell height based on image height - Stack O...

ios iphone uicollectionview
Rectangle 27 0

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    BOPhotoCollectionViewCell* currentCell = ([[collectionView visibleCells]count] > 0) ? [[collectionView visibleCells] objectAtIndex:0] : nil;
    if(cell != nil){
        _index = [collectionView indexPathForCell:currentCell].row;
        [self updateTitle];
    }
}

iPhone: Indexpath.row of UICollectionView - Stack Overflow

iphone uicollectionview nsindexpath
Rectangle 27 0

Write in ViewDidLoad Method

    for (int i=0; i<[imageURLArray count]; i++)
        {
             //Declare Globally
            IMGArray1=[[NSMutableArray alloc] init];

            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[imageURLArray objectAtIndex:i]]];
            NSOperationQueue *urlQue = [[NSOperationQueue alloc] init];
            [NSURLConnection sendAsynchronousRequest:urlRequest queue:urlQue completionHandler:^(NSURLResponse *response,
                                                                                                 NSData *MoblieDatadata, NSError *error)
             {
                 if ([MoblieDatadata length] >0 && error == nil)
                 {
                     UIImage *image = [[UIImage alloc]initWithData:MoblieDatadata];
                     [IMGArray1 addObject:image];

                 }
                 else if ([MoblieDatadata length] == 0 && error == nil)
                 {

                     NSLog(@"Nothing was downloaded.");



                 }
                 else if (error != nil)
                 {
                     NSLog(@"Error happened = %@", error);
                     dispatch_async(dispatch_get_main_queue(), ^{


                     });
                 }
             }];


    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                     cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        examplemycell *myCell = [collectionView
                                        dequeueReusableCellWithReuseIdentifier:@"cell"
                                        forIndexPath:indexPath];

        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        myCell.imageView.image = image;

        return myCell;
    }
    #pragma mark -
    #pragma mark UICollectionViewFlowLayoutDelegate

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        return image.size;
    }

//For setting spacing between collectionview cells
//use the delegate method like

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section  
  {
    return 10; // This is the minimum inter item spacing, can be more
  }

And Use this for verticle line spacing between cells

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

you have tried this because it is not working giving me error NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0xa781820

Well i've not used this, please give me time.Or you can take idea from this :)

i have said in question that i have tried this and it is not working

ios - UICollectionview set cell height based on image height - Stack O...

ios iphone uicollectionview
Rectangle 27 0

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    BOPhotoCollectionViewCell* currentCell = ([[collectionView visibleCells]count] > 0) ? [[collectionView visibleCells] objectAtIndex:0] : nil;
    if(cell != nil){
        _index = [collectionView indexPathForCell:currentCell].row;
        [self updateTitle];
    }
}

iPhone: Indexpath.row of UICollectionView - Stack Overflow

iphone uicollectionview nsindexpath