nsindexpath

How can I check if an indexPath is valid, thus avoiding an “attempt to scroll to invalid index path” error?

早过忘川 提交于 2019-12-04 15:03:27
问题 How can I check to see whether an indexPath is valid or not? I want to scroll to an indexPath , but I sometimes get an error if my UICollectionView subviews aren't finished loading. 回答1: You could check - numberOfSections - numberOfItemsInSection: of your UICollection​View​Data​Source to see if your indexPath is a valid one. 回答2: A more concise solution? func indexPathIsValid(indexPath: NSIndexPath) -> Bool { if indexPath.section >= numberOfSectionsInCollectionView(collectionView) { return

Assertion Failure for UITableView selectRowAtIndexPath

笑着哭i 提交于 2019-12-04 06:22:25
I feel like this is an issue that requires special attention... my Google-fu is pretty good but I haven't been able to get anything useful. This is the simplest thing, and yet I can't seem to figure out what the problem is with it. I have a UITableView. It's a subview that my VC calls _form. I'm using it for styling purposes, not really to display data. It has 2 cells. On a certain event, I'm trying to select a different cell, using selectRowAtIndexPath:animated:scrollPosition. When I do this, it SIGABRTS. A simple example: - (IBAction)submitClicked:(id)sender { [_submit setTitle:@"Wha!?"

Issues using NSIndexPath as key in NSMutableDictionary?

99封情书 提交于 2019-12-04 03:34:35
Is there any particular reason why attempting to store and retrieve a value in an NSMutableDictionary using an NSIndexPath as a key might fail? I originally attempted to do this in order to store an NSMutableDictionary of UITableViewCell heights ( self.cellHeights ) for a UITableView . Each time you tapped a UITableViewCell , that cell would either expand or contract between two different heights based on the value stored in the NSMutableDictionary for that particular indexPath : - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSNumber

How to compare two NSIndexPaths?

强颜欢笑 提交于 2019-12-03 23:29:12
I'm looking for a way to test if to index paths are equal, and by equal I mean equal on every level? I tried compare: but it seems not to work, I always get true when compared with NSOrderedSame even if the indexes are definitely not the same. Almost all Objective-C objects can be compared using the isEqual: method. So, to test equality, you just need [itemCategoryIndexPath isEqual:indexPath] , and you're good to go. Now, this works because NSObject implements isEqual: , so all objects automatically have that method, but if a certain class doesn't override it, isEqual: will just compare object

How can I check if an indexPath is valid, thus avoiding an “attempt to scroll to invalid index path” error?

孤人 提交于 2019-12-03 22:04:27
How can I check to see whether an indexPath is valid or not? I want to scroll to an indexPath , but I sometimes get an error if my UICollectionView subviews aren't finished loading. You could check - numberOfSections - numberOfItemsInSection: of your UICollection​View​Data​Source to see if your indexPath is a valid one. A more concise solution? func indexPathIsValid(indexPath: NSIndexPath) -> Bool { if indexPath.section >= numberOfSectionsInCollectionView(collectionView) { return false } if indexPath.row >= collectionView.numberOfItemsInSection(indexPath.section) { return false } return true }

How to check if IndexPath is valid?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 15:27:28
Prior to swift 3, i used to use for example: let path = self.tableView.indexPathForSelectedRow if (path != NSNotFound) { //do something } But now, since i use IndexPath class in swift3, i'm looking for the equivalent for the path != NSNotFound check. Xcode8.3.1 compiler error: "Binary operator '!=' cannot be applied to operands of type 'IndexPath' and 'Int'" Semantically, to consider an indexPath invalid , you need something to check for such as a table view or a collection view. Usually you can consider an indexPath invalid if it represents a row where there is no corresponding data in the

Comparing NSIndexPath Swift

百般思念 提交于 2019-12-03 14:45:12
问题 If I have a NSIndexPath constant declared for a UITableView, is it valid to compare using the == operator? This is my constant declaration: let DepartureDatePickerIndexPath = NSIndexPath(forRow: 2, inSection: 0) And then my function: override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat { var height: CGFloat = 45 if indexPath == DepartureDatePickerIndexPath{ height = departureDatePickerShowing ? 162 : 0 } else if indexPath ==

didSelectRowAtIndexPath returns wrong IndexPath

梦想的初衷 提交于 2019-12-03 14:15:59
问题 I have encountered a really puzzling bug. The first row of my UITableView returns 1 and the second one returns 0 in the indexPath! How is that even possible? In my `-(void)viewDidLoad` everything is still fine. I am highlighting the first row successfully with currentRow = 0; [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:currentRow inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone]; I have the variable currentRow for tracking which row is selected (another

UICollectionView indexPathsForVisibleItems don't update new visible cells

你离开我真会死。 提交于 2019-12-03 12:56:49
I have a ViewController with a CollectionView inside. When the view loads, the visible cells (9 cells) are shown correctly. When I scroll down, I want to load the visible items in the collectionview with loadImagesForOnscreenRows by calling the indexPathsForVisibleItems for partnerCollectionView. But when loadImagesForOnscreenRows the indexPathsForVisibleItems has allways the first 9 cells in it, even when cells 10 to 18 should be visible on the screen. The code I use is: #import "PartnerListViewController.h" #import "AppDelegate.h" #import "Partner.h" #import "ImageLoader.h" #import

Is there a way to automatically scroll to the bottom of a UICollectionView

别来无恙 提交于 2019-12-03 08:31:48
So I'm currently working on a project that has a button that adds cells to a UICollectionView and then needs to automatically scroll to the last cell (i.e. the bottom of the UICollectionView). I've found the method scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated But now I'm getting stuck at trying to find the indexPath of the last object in the CollectionView. The problem seems to lie in that I've been trying to think of the cells in the UICollectionView as an array (can't enumerate through them, doesn't