views:

252

answers:

2

I am writing a "tweetie 2" like swipe functionality, but have run into what I hope is the last stumbling block.

When a user swipes across a table row the "controls" view animates as expected, but when the row is selectd, didSelectRowAtIndexPath is fired off. The desired result is for when the "controls" view is visible to disable the didSelectRowAtIndexPath method or for a lack of a better phrase...stop the responder chain for continuing past the "controls" view.

The uitouch delegate methods are used/being called in the custom uitablviewcell.

+2  A: 

What about setting/unsetting the value of allowsSelection in UITableView as needed?

bpapa
+1  A: 

A bit of logic should do the job here. Let's say you add this property to your UITableViewController subclass:

NSIndexPath *indexPathForCellInUtilityMode;

When the user triggers the cell's utility view, your cell does this:

NSIndexPath *cellIndexPath = [parentViewController.tableView indexPathForCell:self];
parentViewController.indexPathForCellInUtilityMode = cellIndexPath;

Then:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


if ([indexPath compare:indexPathForCellInUtilityMode] != NSOrderedSame) {
//Do whatever you're normally doing in this method.
}

So you'll disable selection for the affected cell while still allowing the user to interact with other visible cells.

Danilo Campos
Sorry for the delayed response, but how do I set the parentViewController property without alloc/init the RootViewController (which will take place in my custom cell) or is that the expected route?
Cory Wiles
No worries. Since you're creating a custom cell subclass, you can easily add a property to it called parentViewController. Make sure the property is assign rather than retain to prevent retain cycles. Then, when the viewController instantiates the cell, set `cell.parentViewController = self;` Make sense?
Danilo Campos
@Danilo I think it does. I am going to come up with some sample code to post this week so that my assumptions can be verified. Thanks for all your help.
Cory Wiles