Article View: comp.sys.next.programmer
Article #477Delegate methods
From: Robert D. Nicholson
Date: Fri, 07 Aug 1992 04:34
Date: Fri, 07 Aug 1992 04:34
52 lines
2110 bytes
2110 bytes
I am finding im still using case analysis with delegate methods, for example.
I have two textFields for which I need some similar action for. There textDidGetKeys
looks like this.
- textDidGetKeys:textObject isEmpty:(BOOL)flag
{
Matrix *matrix = nil;
TextField *textField;
const char *s;
int i, max;
textField = [textObject delegate];
if ([textField isEqual:employeename])
matrix = [employees matrixInColumn:[employees lastColumn]];
else if ([textField isEqual:description])
matrix = [rooms matrixInColumn:[rooms lastColumn]];
s = [textField stringValue];
max = [matrix cellCount];
[window disableFlushWindow];
[matrix clearSelectedCell];
if (!flag) {
for (i = 0; i < max; i++) {
id cell = [matrix cellAt:i :0];
if (strncmp(s,[cell stringValue],strlen(s)) == 0) {
[matrix selectCellAt:i :0];
[matrix scrollCellToVisible:i :0];
break;
}
}
}
[matrix display];
[[window reenableFlushWindow] flushWindow];
return self;
}
Notice the if tests, what can be done to elemimate this, (does it have to be eliminated?)
Short of creating a DelegateAgent class where the number of instances = number of
textFields? Sounds reasonable, except that you then won't be able to connect
textDelgate in IB then, I guess you can do this in code, but as we always say we
would like to use IB at much as possible.
case analysis isn't a particularly object-oriented way of doing things.
--
Quote of the day
"If Andrew Stone can do it, well Im certainly gonna give it a try"
Technical Details
Message-ID:
<1992Aug7.043403.10603@monu6.cc.monash.edu.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!sdd.hp.com!mips!mips!munnari.oz.au!bruce.cs.monash.edu.au!monu6!ede978eShow Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!sdd.hp.com!mips!mips!munnari.oz.au!bruce.cs.monash.edu.au!monu6!ede978e From: ede978e@monu6.cc.monash.edu.au (Robert D. Nicholson) Subject: Delegate methods Message-ID: <1992Aug7.043403.10603@monu6.cc.monash.edu.au> Organization: Monash University, Caulfield Campus Date: Fri, 7 Aug 1992 04:34:03 GMT Lines: 53