Cancellable button like in iTunes, or "Delete"-confirmation?

13 views
Skip to first unread message

Fredrik Olsson

unread,
Apr 27, 2010, 1:34:38 PM4/27/10
to cocoahead...@googlegroups.com, cocoaheads...@googlegroups.com
Hi.

The big red "Delete"-button for confirming a deletion on a table view,
as well as the "price/buy"-button in the iTunes-store app, are both
cancellable by tapping anywhere but inside the actual button.

I would like to implement the same behavior in my own app.

What I have done so far is to set the accessoryView as a
"Download"-button, and the editableAccessoryView as the
"Confirm"-button. This way I can nicely switch between then by calling
-[UITableViewCell setEditing:YES animated:YES].

Problem is that I can not for my life figure out how to make it
cancelable by tapping outside. Any tips?

// Fredrik

--
You received this message because you are subscribed to the Google Groups "CocoaHeads Øresund" group.
To post to this group, send email to cocoahead...@googlegroups.com.
To unsubscribe from this group, send email to cocoaheads-ores...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cocoaheads-oresund?hl=en.

Felix Holmgren

unread,
Apr 27, 2010, 2:37:33 PM4/27/10
to cocoahead...@googlegroups.com, cocoaheads...@googlegroups.com
The only sure way I know of to intercept *all* touch events is to override

- [UIView hitTest:(CGPoint)point withEvent:(UIEvent *)event]

Use a subclass of UIView as your main view, call super's
implementation, and before returning the value, check if it's a
selected UITableViewCell. If it's not, deselect the cell, either
directly if you you have the index path saved, or by iterating through
all visible cells.

It would be great to hear of other solutions, but I rely on this
slightly crude method any time I have to do something like this. It
can be very useful to override this method in UIWindow for example.

/Felix

2010/4/27 Fredrik Olsson <pey...@gmail.com>:
--
Holmgren Interstellar
S:t Gertrudsgatan 4C
S-211 25 Malmö
Sweden
tel: +46 704 452 469

Patrik Svensson

unread,
Apr 27, 2010, 3:45:27 PM4/27/10
to cocoahead...@googlegroups.com, cocoaheads...@googlegroups.com
Hi.
What about using a transparent button covering the whole screen placed behind your "Delete" button?


BR,
Patrik

Felix Holmgren

unread,
Apr 27, 2010, 3:51:39 PM4/27/10
to cocoahead...@googlegroups.com
That would swallow all events so you couldn't interact with the rest
of the screen...

2010/4/27 Patrik Svensson <a.patrik...@gmail.com>:
--
Holmgren Interstellar
S:t Gertrudsgatan 4C
S-211 25 Malmö
Sweden
tel: +46 704 452 469

Fredrik Olsson

unread,
Apr 29, 2010, 7:14:36 AM4/29/10
to cocoahead...@googlegroups.com, cocoaheads...@googlegroups.com
That is the way I ended up.

I added a category on UIWindow with a new exclusiveCancelableView property.
* If the exclusive view is the hit-test view then UIWindows
hitTestwithEvent: works as normal.
* If the hit-test view is something else, then I post a
CWExclusiveViewShouldCancelNotitification.

Works like a charm. Plan to write down a short blog-post on it when I
have some time to spare.


// Fredrik
Reply all
Reply to author
Forward
0 new messages