logo
down
shadow

UICollectionView didSelectItemAtIndexPath, how to pass random images from cellForItemAtIndexPath?


UICollectionView didSelectItemAtIndexPath, how to pass random images from cellForItemAtIndexPath?

By : user2950190
Date : November 17 2020, 11:52 AM
I wish did fix the issue. I'm using Parse database to show an array of images in my UICollectionView with a random index, but I need to show them in an alert when the user selects the item, so how can I retrieve the images properly in didSelectItemAtIndexPath ?! !! , Short answer
code :
    NSString *const identifier = @"cell";

    -(void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

        UIImage *image;
        for (UIView *view in [cell subviews]) {
            if ([view isKindOfClass:[UIImageView class]]) {
               image = [(UIImageView*)view image];
               break;
            }
        }

        if (image) {
            //do what you want to do
        } else {
            //something goes wrong
        }
    }
    NSMutableArray *randomImageNameList = [NSMutableArray array];
    NSDictionary* dictionary;
    NSUInteger count = [appDelegate.immaginihome count];
    NSString *imageNameKey = @"ImmaginiHome";
    for (int i = 0; i < count; i++) {
        dictionary = [appDelegate.immaginihome objectAtIndex:(arc4random() % count)];
        [randomImageNameList addObject:[dictionary objectForKey:imageNameKey];
    }


Share : facebook icon twitter icon
UICollectionView cellForItemAtIndexPath is nil

UICollectionView cellForItemAtIndexPath is nil


By : codydane
Date : March 29 2020, 07:55 AM
To fix the issue you can do From the UICollectionView docs (emphasis my own)
UICollectionViewCell background color change works in cellForItemAtIndexPath but not didSelectItemAtIndexPath

UICollectionViewCell background color change works in cellForItemAtIndexPath but not didSelectItemAtIndexPath


By : user2286912
Date : March 29 2020, 07:55 AM
With these it helps I can change my collection view cell background color in cellforitematindexpath but not in didselectitematindexpath using the code below (i only change the color in one place however). How does this happen? , Several things wrong here.
What is wrong if cellForItemAtIndexPath: is called in didSelectItemAtIndexPath:

What is wrong if cellForItemAtIndexPath: is called in didSelectItemAtIndexPath:


By : Seth
Date : March 29 2020, 07:55 AM
With these it helps The collection view is caching instances of cells for you and you dequeue them when you create the cell at an index path. The collection view is making some assumptions about what's going on when you do this, so if you start making multiple requests for cells at the same index path strange things start to happen. Sometimes this results in visual issues, sometimes interaction issues.
If you want to get the cell at a specified index path you should ask the collection view directly instead of using your own delegate method, this will give you the existing cell on screen rather than a new cell.
didSelectItemAtIndexPath of UICollectionView is not called

didSelectItemAtIndexPath of UICollectionView is not called


By : Kalyani Suman
Date : March 29 2020, 07:55 AM
To fix the issue you can do First of all thanks for give me the hints to solve my problem. Following them and trying to assign the parent controller as delegate of ccvc.collectionView, It said that there wasn't any delegate in the child ViewController. My problem was that I thought that if assigned both delegate and dataSource via Storyboard It would work out, but It wouldn't.
So I decided to implement both Delegate and Datasource protocols in parent controller, remove child controller and It works like a charm now. Maybe I was misunderstanding concepts when I used the Storyboard. for your help!
UICollectionView not calling didSelectItemAtIndexPath

UICollectionView not calling didSelectItemAtIndexPath


By : Ilham Firdaus
Date : March 29 2020, 07:55 AM
around this issue I had a similar problem and it turned out I was using the same cell reuse identifier in two different collection views
Related Posts Related Posts :
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org