logo
down
shadow

IOS: Selecting UICollectionView Cell by Long Press


IOS: Selecting UICollectionView Cell by Long Press

Content Index :

IOS: Selecting UICollectionView Cell by Long Press
Tag : iphone , By : 40a
Date : November 29 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Long press tap gesture recogniser for UICollectionView Objective-c


Tag : ios , By : James Dio
Date : March 29 2020, 07:55 AM
around this issue I am using a UICollectionView in my ViewController for displaying images and i want that user should be able to delete photos on long press, but i am not able to detect long press gesture. I have read all the previous discussions and tried to implement them in my project also but none of them worked for me. , Enable user interaction for your imageview by below line
imgview.userInteractionEnabled =YES;
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[gestureRecognizer addTarget:self action:@selector(imgLongPressed:)];
gestureRecognizer.delegate = self;
imgview.userInteractionEnabled =YES;
[imgview addGestureRecognizer: gestureRecognizer];

- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
    UIImageView *view_ =(UIImageView*) sender.view;
    CGPoint point = [sender locationInView:view_.superview];

    if (sender.state == UIGestureRecognizerStateBegan)
    {

    }
    else if (sender.state == UIGestureRecognizerStateChanged)
    {

    }
    else if (sender.state == UIGestureRecognizerStateEnded)
    {

    }

}

Last cell is highlighted when selecting first cell in UICollectionView


Tag : ios , By : Yst
Date : March 29 2020, 07:55 AM
should help you out I found this link on S.O. which was helpful. To solve the problem I simply added the following code to my func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {}.
Code...
 if collectionView.indexPathsForSelectedItems?.contains(indexPath) == true {
        print("This cell is selected \(indexPath.item)")
        cell?.layer.borderWidth = 3
        cell?.layer.borderColor = UIColor.yellow.cgColor
    }else{
        cell?.layer.borderWidth = 0

    }

UICollectionView Cell not changing upon selecting


Tag : swift , By : Dominique Vocat
Date : March 29 2020, 07:55 AM
may help you . My guess would be that you are creating a new instance of cell instead of using the one in the collectionView
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    // Change this line
    let cell = collectionView.cellForItemAtIndexPath(indexPath: indexPath)

    print(cell.statLabel.text)
    cell.backgroundColor = UIColor.yellow
    collectionView.reloadData()

}
var selectedStatHeaders: Set<Int>()

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

    cell.statLabel.text = statHeaders[indexPath.row]
    cell.statLabel.textColor = UIColor(red:0.31, green:0.31, blue:0.31, alpha:1.0)
    // Reset/configure cell each reload
    if selectedStatHeaders.contains(indexPath.row) { // Can also make this into a ternary
      cell.backgroundColor = UIColor.yellow
    } else {
      cell.backgroundColor = UIColor.whit
    }
    return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    selectedStatHeaders.insert(indexPath.row)
    collectionView.reloadItemsAtIndexPath(indexPath: indexpath)
}

UICollectionView is scrolling when selecting a cell


Tag : ios , By : user183345
Date : March 29 2020, 07:55 AM

ios UICollectionView cell selecting and deselecting issue


Tag : ios , By : Helpful Dude
Date : March 29 2020, 07:55 AM
Does that help while scrolling cells are reused that time cellForItemAt will call so you need to change some modification in your code
func collectionView(_ collectionView: UICollectionView, 
didSelectItemAt indexPath: IndexPath) {
 selectedIndexPath = indexPath
 YOUR_COLLECTION_VIEW.reloadData()
}
if indexPath ==  selectedIndexPath {
     cell.contentView.backgroundColor=UIColor.purple
     cell.backgroundColor = UIColor.purple
} else {
     cell.contentView.backgroundColor = UIColor.orange
     cell.backgroundColor = UIColor.orange
}
Related Posts Related QUESTIONS :
  • get SSL Broken pipe error when try to make push notification
  • How to store UISegmentedControle state in NSUserdefaults
  • What developer conferences/code camps would one go for mobile development?
  • How can I intercept the StoreKit "buy dialog" to make a MBProgressHUD / UIProgressView show up correctly and a
  • Is Appcelerator Titanium now banned on the iPhone?
  • Data storing in plist works in simulaor but not in device
  • UISearchDisplayController and search performance with lots of data
  • Why is my UIViewController initializer never called?
  • Can you run a blender game on an iphone or droid?
  • CGBitmapContextCreate on the iPhone/iPad
  • Problem pushing multiple view controllers onto navigation controller stack
  • addSubview like modal
  • How create UIImage from bytes?
  • UITableView section index overlaps search bar
  • iPhone Mapkit: How can I get a real business name/address from a longitude/latitude?
  • animating adding/removing layers on iPhone
  • iPhone 4.0 Beta compile for 3.1.3
  • how to implement RSA algorithm in iphone application?
  • IPhone SDK Default NSUserDefaults
  • Pushing mail from postfix to iPhone
  • UISegmentedControl tint color on touch
  • button inside table view cell shows highlighted state on tapping on cell
  • best practice to obtain time zone for iPhone vs iPod Touch
  • UITableViewCellStyleDefault image size
  • How to copy a wchar_t into an NSString?
  • Custom size app screen on iPad
  • Interface Builder Does Not Recognize Toolbar Buttons
  • Where can I download iPhone SDK 3.1?
  • iPhone, memory / autorelease objects
  • iPhone App too large for SpringBoard to launch?
  • NSDateFormatter only works on simulator?
  • How to get tabs like zipcar app?
  • What is the iPhone simulator IP address?
  • From a 3D modeler to an iPhone app - what are best practices?
  • How to produce an iphone app which calculates the battery status?
  • UIView animation -- horizontal page curl... like a book?
  • How to ensure YouTube API only returns videos that are streamable on iPhone?
  • CABasicAnimation delegate for animationDidStop?
  • How to test if a web service is available
  • iphone app crash, crash log posted
  • Quartz 2D or OpenGL ES? Pros and cons in the long term, possibility of migration to other platforms
  • How do I get Core Data to create an SQLite DB from my Managed Object Model
  • Can a method return an NSRange?
  • Switching xib's in iPhone SDK?
  • iPhone: value of selectedIndex for tab should be consistent, but isn't
  • how to send MMS from the iphone by programming?
  • Is it a good idea to use ASIHTTPRequest library with three20?
  • Auto launch the video player in Android from the browser like an iPhone does
  • Subview Doesnt AutoSize When Added to Root View Controller
  • How to implement UITableView with multiple columns and sideways scrolling
  • How to run/port MongoDB on iPad?
  • How to insure MFMailComposeViewController doesnt send email when body is not empty?
  • How to add ANY language in app description on AppStore? Tremendous impact on downloads!
  • Play multiple audio files using AVAudioPlayer
  • Infinite loop when adding CATiledLayer to UIView
  • How can I detect if an iPhone OS device has a proximity sensor?
  • setNeedsDisplayInRect: paints a white rectangle only
  • iPhone in App purchase : Working but Not
  • How do I debug production push notifications using Xcode?
  • Possible to play a sound without stopping music?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com