I personally wouldn't use exceptions to handle what are basically known coding 
bugs, e.g., choosing not to add an extra line or two of code to do range 
checking when you know ahead of time that there are strings that you don't 
consider valid.

And whether or not you continue using your current exception-based model, the 
determination of what constitutes valid vs. error state should still be 
determined in your model and/or controller classes, not in a view 
(UITableViewCell) class. The view class should only be displaying the current 
state specified by the controller. That might mean that you need to add, for 
example, a "validState" property to your UITableView subclass that the 
controller sets and then the view uses to determine whether to display its 
"valid" or "error" representation. Then you get the desired behavior: no 
exceptions generated in the view class, no having to back out existing drawing, 
etc.


On Jul 24, 2010, at 12:49 PM, Malayil George wrote:

> I am extracting strings from an NSString and I get NSRange exceptions. I 
> could always first check to see if the range is valid, but, figured I would 
> save myself the effort and use the exception handling mechanism. Problem is 
> that after I extract and draw a few strings of valid ranges, I run into the 
> exception. So, at this point I would like to clear out all drawing and do my 
> error string handling bit.
> 
> Thanks
> George
> 
> On Thu, Jul 22, 2010 at 9:16 AM, Steve Christensen <puns...@mac.com> wrote:
> 
>> I think a more basic question is what you're doing in -drawRect that would 
>> generate an exception in the first place. Typically a view should already 
>> have access to any relevant resources (strings, images, whatever) before 
>> -drawRect is ever called. Assuming that the exception is a reasonable error 
>> case and not a bug, it seems like it should be handled in your model and/or 
>> controller class and that the view is then configured to display its error 
>> "look."
>> 
>> 
>> On Jul 21, 2010, at 8:14 PM, Malayil George wrote:
>> 
>>> I am trying to draw to a custom UITableViewCell. The UITableViewCell has
>>> a UIView and I do some custom drawing in it's drawRect. However, in some
>>> cases while doing the drawing I run into an exception. I catch the exception
>>> and at this point, want to clear all existing drawing in the view and start
>>> again. My approach so far has been
>>> 
>>> backgroundColor = [UIColor clearColor];
>>> //Custom draw code in try block
>>> 
>>> //If exception
>>> backgroundColor = [UIColor whiteColor];
>>> CGContextFillRect(context, rect); //context is current graphics context and
>>> rect is bounds of the UIView
>>> //Different draw code below
>>> 
>>> While this works, it messes up selecting the cell. On selecting the cell,
>>> the view remains white, with it's surrounding blue. In cells without the
>>> exception, selecting it renders the whole cell blue (which is what I would
>>> like).
>>> 
>>> Is there anyway to discard all drawing in the cell without resorting to
>>> filling it with white or some other color?
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to