tags:

views:

258

answers:

2

I'm trying to avoid putting a button in my UITableViewCell subclass so that I don't unnecessarily lag up the scrolling speed.

The button would push another view onto the navigation stack.

I figured since UITableView already has built-in and optimized methods for managing this, that simply limiting the touchable area of my cells would be the easiest and most effective way of achieving my goal.

I really have no idea how I would implement something like this. I have a feeling I would have to override pointInside:withEvent: or hitTest:withEvent:, but I'm not sure how. Managing touchEvents and the UIResponder stuff still escapes me.

So my question is ultimately, in my rootViewController, how would I implement that selecting a row will only work at lets say 220,10,40,40 ?

Thanks!

A: 

A UITableViewCell should have a normal selection style(i.e. not UITableViewCellSelectionStyleNone), generally speaking. You shouldn't have buttons on cells that you are reusing an arbitrary number of times.

If you're using a lot of UIButtons in your UITableView, you may want to rethink how your UI is designed.

You can't easily (to my knowledge) change "selectable" parts of a cell - the whole cell must be selectable no matter what(you can set the style to no selection, but you'll still recieve touch updates).

Mike
I am aware of this. Considering the nature of the data though, pressing a special "details" button in the top right corner is more intuitive to the user.Which makes me think... maybe the right approach would be to overide the UITableViewCellAccessoryDetailDisclosureButton?
Mike A
P.S.: It's good to see that the "Mike" username isn't wasted on an inactive user ;)
Mike A
Is there a way of changing the detail disclosure button? That could be a whole separate question.
Mike A
Well, what actions can a user take on a row? Generally speaking, it should just be 2 things: either the row can be pressed, at which point the UINavigationController has a new view pushed on its stack, or the user can swipe to delete an entry. Perhaps you should consider putting the details button in the pushed-on view after the user selects the cell.
Mike
You can change the accessory controller by setting the cell accessory type to `UITableViewCellAccessoryNone` and manually putting on your own indicator when you make the cell.
Mike
That isn't exactly true. But there are cases where if you press the cell it pushes one view, and when you press the detail disclosure button, it pushes another. For example Favorites on your iPhone.
Mike A
The last time I tried to make a custom accessory, the `tableView:accessoryButtonTappedForRowWithIndexPath:` delegate method was not called on touches to it, so that's the only snag with not using the built in detail disclosure button. Apple's passive aggressive way of enforcing UI consistency?
Danilo Campos
Attacus: That's true, but users will only expect that type of behavior for the detail disclosure button, and nothing else, so you shouldn't use a custom button if you're going down that route.
Mike
+1  A: 

The behavior you're describing sounds like a job for UITableViewCellAccessoryDetailDisclosureButton, actually. If you're going to be pushing another view onto the stack but don't want to do that when the user selects the cell proper, use a detail disclosure button to maximize your consistency with existing UI convention. It's hard to say without more information.

As for doing the work necessary to detect touches in a sub-region, that may be more trouble than it's worth. True, adding subviews to a cell incurs a compositing cost but if you're only talking about one button, and a button whose background you can set to opaque, you'll probably be just fine. The alternative is reinventing the wheel to recreate button behavior in a subregion of the cell and that doesn't sound like functionality that will be much fun to maintain as the SDK matures.

That said, adding views to a cell doesn't incur a compositing cost per se, it's drawing those views that's the trouble. So if you really wanted to go nuts on the optimization, you could create a pre-rendered cell background image that includes the appearance of a button you want and then place a custom, image-free, see-through UIButton instance right over top of it. Nothing to draw, so no additional compositing cost. Worth a shot.

You didn't come here for a premature optimization speech, so I won't bother with one, but I say just do the cell with a normal button for now, make sure you like how the functionality feels to use then optimize toward the end if you're looking at performance that you're not happy with.

Danilo Campos
I have a very umm, detailed data index, and sometimes it's not practical to navigate in the normal iPhone fashion ie: Big > Medium > Small > Detail View. In my case the specific button in the detail view (a UITableView with custom cells) when you would press the button, you'd see the details of the selected object, followed by lets say the 20 objects before and after it at the bottom of the data hierarchy. Does that make sense? The detail disclosure button isn't as intuitive as I'd like it to be.
Mike A
You know your UI and you know which rules you need to break for your specific circumstances, so try it, make sure it feels right, then refine from there. Have users who have no idea what you're building try it out. Detail disclosure can be unintuitive for even its normal uses, I've found from support emails. So convention is a guidepost, not a straitjacket. If the detail disclosure won't do it, try out the pre-baked cell background with a see-through UIButton. Shouldn't hurt your performance and it won't be a pain to build or maintain.
Danilo Campos
Very good idea Danilo, thanks.
Mike A