nsindexpath

Comparing NSIndexPath Swift

泄露秘密 提交于 2019-12-03 04:32:40
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 == ArrivalDatePickerIndexPath { height = arrivalDatePickerShowing ? 162 : 0 } return height } This certainly works

didSelectRowAtIndexPath returns wrong IndexPath

旧时模样 提交于 2019-12-03 04:08:18
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 control changes according to which one is currently selected). Now in my `didDeselectRowAtIndexPath`

How to create NSIndexPath for TableView

老子叫甜甜 提交于 2019-12-03 01:33:32
问题 I need delete row 1 of a table in a function I have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defined. How can I create an indexpath like this? An array with the int {1} as its only member will crash; the NSLog message states that the section needs to be defined as well. *Edit -> Code relating to cell delete: NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0]; NSArray *myArray = [[NSArray alloc] initWithObjects:myIP,

isEqual doesn't always work for NSIndexPath? What can I use in its place?

天大地大妈咪最大 提交于 2019-12-02 20:12:44
I've got some code that relies on comparing two NSIndexPaths and executing different code based on their equality or lack thereof (using -isEqual). Most of the time it works properly, but sometimes it doesn't. I've used the debugger console to test the two indexpaths during code execution, and they look identical to me. Here's the code: - (BOOL)selectedStreetIsSameAsLastSelectedStreet { return [self.indexPathOfSelectedStreet isEqual:self.previousObject.indexPathOfSelectedStreet]; } Here's the output during the execution of the code: (gdb) po self.indexPathOfSelectedStreet <NSIndexPath

didDeselectRowAtIndexPath indexPath is nil

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 14:17:22
问题 I have a TableViewController which implements the TableViewDelegate methods: public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell cell.viewModel?.active = true } public override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) as!

How to create NSIndexPath for TableView

半城伤御伤魂 提交于 2019-12-02 13:51:40
I need delete row 1 of a table in a function I have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defined. How can I create an indexpath like this? An array with the int {1} as its only member will crash; the NSLog message states that the section needs to be defined as well. *Edit -> Code relating to cell delete: NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0]; NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil]; // [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation

didDeselectRowAtIndexPath indexPath is nil

别说谁变了你拦得住时间么 提交于 2019-12-02 12:22:24
I have a TableViewController which implements the TableViewDelegate methods: public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell cell.viewModel?.active = true } public override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell cell.selectedStateImageView.hidden = true cell.viewModel?.active = false } Please note that I

cellForRowAtIndexPath: crashes when trying to access arrays objectAtIndex:indexPath.row

醉酒当歌 提交于 2019-12-02 06:19:28
I am loading in data to a UITableView , from a custom UITableViewCell (own class and nib). It works great, until I try to access the objectAtIndex:indexPath.row for some arrays. I'll post my code first, it will probably be easier for you to understand what I mean then. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil){ NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed

Get last cell in a UITableview section

不想你离开。 提交于 2019-12-01 15:05:49
I have a section in UITableView which has multiple rows. I wish to get the last row or the last cell of the section to add a disclosure indicator on it. One way I am thinking to use is: NSIndexPath *lastCellIndexPath = [NSIndexPath indexPathForItem:[self.tableView numberOfRowsInSection:2]-1 inSection:2]; Is there any other best way to get the cell or indexpath of the last cell on a section? johnMa NSInteger totalRow = [tableView numberOfRowsInSection:indexPath.section];//first get total rows in that section by current indexPath. if(indexPath.row == totalRow -1){ //this is the last row in

Get last cell in a UITableview section

孤人 提交于 2019-12-01 13:58:33
问题 I have a section in UITableView which has multiple rows. I wish to get the last row or the last cell of the section to add a disclosure indicator on it. One way I am thinking to use is: NSIndexPath *lastCellIndexPath = [NSIndexPath indexPathForItem:[self.tableView numberOfRowsInSection:2]-1 inSection:2]; Is there any other best way to get the cell or indexpath of the last cell on a section? 回答1: NSInteger totalRow = [tableView numberOfRowsInSection:indexPath.section];//first get total rows in