uicollectionviewcell

caching images in collectionViewCell in Swift?

自闭症网瘾萝莉.ら 提交于 2019-12-04 11:22:28
I have images in my collectionViewCell's that are fetched and parsed via NSURLRequest, how do I cache these images so they don't have to start a new request with every single appearance/disappearance of the view? here is my code that fetches the images: class funnyPicture: NSObject { var pfPicture : PFObject var coverImage : UIImage! init(pfPicture: PFObject) { self.pfPicture = pfPicture } func fetchCoverImage(completion: (image: UIImage?, error: NSError?) -> Void) { let urlString = self.pfPicture["funnyPictures"] as! String let url = NSURL(string: urlString) let request = NSURLRequest(URL:

Label Outlet On Custom UICollectionViewCell In Swift Causing Optional.None Crash

断了今生、忘了曾经 提交于 2019-12-04 11:13:54
问题 I have a collectionViewController that I want to display a bunch of custom UICollectionViewCells with some labels on them. Unfortunately whenever I try and access the custom UICollectionViewCell's label it causes a crash with: Console fatal error: Can't unwrap Optional.None Window Thread1: EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP, subcode=0x0) I'm trying to access the label like so: cell.name.text = names[indexPath!.item] Perhaps this comes from my outlet label being nil? But looking around

pre select/highlight UICollectionViewCell on first load of view

时光总嘲笑我的痴心妄想 提交于 2019-12-04 10:15:14
问题 Im trying to preselect the first object/UICollectionViewCell in the UICollectionView? I have tried: self.dateCollectionView.allowsMultipleSelection=NO; [self.dateCollectionView selectItemAtIndexPath:0 animated:YES scrollPosition:UICollectionViewScrollPositionLeft]; [self collectionView:self.dateCollectionView didSelectItemAtIndexPath:0]; [self.dateCollectionView reloadData]; in viewDidLoad . Here are my UICollectionView methods; -(NSInteger)collectionView:(UICollectionView *)collectionView

How to resize UICollectionViewCell in iPhone 6 and 6 Plus using autolayout

戏子无情 提交于 2019-12-04 10:14:03
I'm working in a iOS project where i use collectionView using Autolayout and SizeClasses. custom UICollectionViewCell xib is used. Where i reuse custom cell in collectionView presenting two cells like below image in iPhone 5s. problem is while running the same project in iPhone 6 and 6 Plus, the cells are not resizing there is space between cells you can see it below. which is resizing in xib when the size of cell is increased and select update frames but not resizing for iPhone 6. Answers provided by other SO posts didn't helped. Math trick recall square root Number 33 = items count! You can

How can I override a setter from a SuperClass in Swift with Xcode 6.3 Beta2?

浪尽此生 提交于 2019-12-04 10:10:10
问题 My SuerClass is UICollectionViewCell which has a property: var selected: Bool My class is MyClass : UICollectionViewCell { func setSelected(selected: Bool) { super.selected = selected // do something } } The former worked well in Xcode 6.2 but in Xcode 6.3Beta2 it raises an error: Method 'setSelected' with Objective-C selector 'setSelected:' conflicts with setter for 'selected' from superclass 'UICollectionViewCell' with the same Objective-C selector How can I fix this to work with Xcode 6.3

XCode 6 UICollectionview viewwithtag not working

旧巷老猫 提交于 2019-12-04 10:09:39
Seems XCode 6 is different in using viewwithtags then XCode 5 was. I am using the following code in XCode 6 with Storyboards. 50 cells are created but the label is not visible.Everything is set correctly like the tag etc. If I use the "old" XCode 5 way to do it with Register cell classed it seems to work for iOS 7 but in iOS 8 the data is not passed to the label until I start to scroll. static NSString * const reuseIdentifier = @"MyCell"; - (void)viewDidLoad { [super viewDidLoad]; // Register cell classes [self.collectionView registerClass:[UICollectionViewCell class]

UICollectionCell to call method in CollectionViewController

风格不统一 提交于 2019-12-04 10:02:28
I have a standard view controller that contains a collection view. I am populating the collection view with custom cells created from a custom subclass of UICollectionViewCell . What is the best practice of calling a method in the collection view class from within the collection view cell class Why doesnt the following init get called in my collection view cell class, I thought this would be called when the collectionView class creates my cells. (id)initWithFrame:(CGRect)frame The reason I want to do this is because I am deleting a collection view cell, the delete function is inside the

UICollectionView crashes randomly because of highlighting issue

女生的网名这么多〃 提交于 2019-12-04 09:22:30
I have a UICollectionView on iOS7 which crashes randomly when intense scrolling. I enabled zombies and found that it gives me an error saying: *** -[NSIndexPath section]: message sent to deallocated instance 0x17dbc970 I believe this is due to an Apple error described here . Apparently, the app crashes when someone highlights a cell while scrolling fast, and then the OS tries to unhighlight it when it moves off screen, when it ceases to exist. The proposed solution is to disable the userInteractionEnabled property of the cell and then handle the selection using UIGestureRecogniser . Has anyone

NSRangeException when deleting last UICollectionViewCell

风格不统一 提交于 2019-12-04 06:30:07
问题 I have a UICollectionView with 1 section. The user can delete cells from the collection, and I use this code for removal: [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:i inSection:0]]]; [self.media removeObjectAtIndex:i]; } completion:nil]; This works fine for every cell except for the last cell in the collection, which crashes the app every time with the error: Terminating app due to uncaught exception

Multiple Cells for Comments and Reply in a CollectionView

强颜欢笑 提交于 2019-12-04 06:04:03
问题 I have two different cells types one is for comments and the other one for replies. I'm trying to render them in the same collectionView and then maybe grouping them like so: each comment with a certain id to have under it its replies. However, with any attempt, I failed. How would you go about it? private var comments = [Comment]() private var replies = [Reply]() var items: [Any] = [] override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int