views:

1231

answers:

2

I have a RootViewController class which is inherited from UITableViewController. When a cell is deselected by the user I want to enable/disable certain buttons on the toolbar. How do I trap the deselect event?

-(void)tableView:(UITableView *)tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated { if(indexPath.row <= rowNumber) { [viewButtton setEnabled:NO]; [editButtton setEnabled:NO]; } }

I tried using this method but it doesn't seem to execute at all. Any ideas how cam this be done?

+1  A: 

I do not think there is a deselectRowAtIndexPath event, there is a method that you can call to deselect the indexPath, but looking at the SDK I do not see an event for this in the UITableViewDelegate: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html.

Could you enable/disable certain buttons on the toolbar during the didSelectRowAtIndexPath: event?

-Rog

Roger
A: 

This is in the current beta SDK only which means it could be buggy / change / unsupported...

I did noticed that your method declaration doesn't match the SDK (at least, the version I have).

Try removing 'animated:(BOOL)animated'; I don't think it's applicable here.

See line ~345 in UITableView.h, and/or right click on didDeselectRowAtIndexPath and "Jump to Definition", where you'll probably find how the delegate method should be defined.

That said, if your goal is simply to "enable/disable certain buttons when a cell is selected",

  • (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;

should work just fine. This will occur after they select the cell and before it's deselected. 'deselect' has to do more with animation than user interaction. The only reason I can think you would want to use deselect is maybe the aesthetic value of ensuring your event only occurs after the select cell is no no longer highlighted.

nessence