views:

27

answers:

1

Ok so here's my code, it works great:

- (void)textViewDidChange:(UITextView *)textView{
 if (textView==someObject) {
  [detailItem setValue:textView.text forKey:@"someObjectAttribute"];
 }

The problem is that I have lots of textviews instances to test for and I would prefer to find some other way to consolidate the code. I was thinking of something like a switch but I don't see how that would work. Any ideas?

+1  A: 

One way would be to use the integer tag of each view. In your code, you’d have an enum like:

enum
{
    kThingView,
    kOtherView,
    ...
};

Each view's tag is set appropriately in IB or when setting up the view programatically. Then:

- (void) textViewDidChange:(UITextView *)textView
{
    switch (textView.tag)
    {
        case kThingView:
            ...
    }
}
Ahruman