Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is -didDeselectRowAtIndexPath not being called?

I created a fresh project (Xcode 4, Master-Detail application) just to see if I'm doing something wrong, but I still have the same problem. I want to call -reloadData when the user deselects a cell, so this is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     [tableView deselectRowAtIndexPath:indexPath animated:YES];     NSLog(@"%s", __PRETTY_FUNCTION__); }  -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {     NSLog(@"%s", __PRETTY_FUNCTION__);     [tableView reloadData]; }  -(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {     NSLog(@"%s", __PRETTY_FUNCTION__);     return indexPath; } 

The problem is that didDeselectRowAtIndexPath and willDeselectRowAtIndexPath don't seem to be called. Is this the expected behavior? The docs for tableView:didDeselectRowAtIndexPath: state

Tells the delegate that the specified row is now deselected.

so I guess that it should work as I thought.

like image 294
phi Avatar asked Mar 22 '12 09:03

phi


People also ask

Why this is used in JavaScript?

“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.

What is the use of this function?

As an object method When a function is called as a method of an object, its this is set to the object the method is called on. In the following example, when o.f() is invoked, inside the function this is bound to the o object. This demonstrates that it matters only that the function was invoked from the f member of o .

What is the use of jest spyOn?

Jest's spyOn method is used to spy on a method call on an object. It is also very beneficial in cases where the Jest mock module or mock function might not be the best tool for the job on hand. While writing unit tests you only test one particular unit of code, generally a function.

How do you mock a function?

You can mock functions in two ways: either you create a mock function to use in test code, or you write a manual mock that overrides a module dependency. Let's take for example the case where we're testing an implementation of a function forEach, which will invoke a callback for each item in a supplied array.


1 Answers

If you call deselectRowAtIndexPath:animated:, the delegate methods tableView:willDeselectRowAtIndexPath: and tableView:didDeselectRowAtIndexPath: message are not sent.

like image 162
freytag Avatar answered Oct 06 '22 17:10

freytag