You're right... mydata is indeed in a view. I have a subclassed UIView to serve as my "component ui" - and it creates instances of subclassed UIViews (containers) which in turn contain subclassed UIButton items. Since I was being quickly lazy in prototyping, I didn't include a view controller for any of these things... my main UIView was the engine for the whole thing. When a user clicked on an item, the button press was dispatched from the container view class back to the main container class - so that layout code, etc. could happen.
Eric On Tue, Aug 3, 2010 at 9:37 PM, Graham Cox <graham....@bigpond.com> wrote: > > On 04/08/2010, at 5:34 AM, Eric E. Dolecki wrote: > > > -(void) buttonClicked:(id)sender > > { > > [[NSNotificationCenter defaultCenter] > > postNotificationName:@"ButtonClicked" > > object:sender]; > > > > > Notwithstanding Quincey's excellent advice, this approach is poor use of > MVC. > > The Button is a view. The thing that responds to the button is the > controller. At that point, the button should have done its job and is no > longer a relevant object in the design. WHAT DOES THE BUTTON DO? This is the > question the controller needs to be asking itself, and messaging the data > model appropriately, not just punting the button object somewhere else for > somebody else to make that call (clue: if ever you send a notification and > the object parameter is not 'self', you need to asking hard questions about > why that is). The controller is not doing its job here, and you've made an > unnecessary link between view and model. > > > - (id)initWithFrame:(CGRect)frame { > > if ((self = [super initWithFrame:frame])) { > > mydata = [[NSArray alloc] init]; > > menuItems = [[NSMutableArray alloc] initWithCapacity:40]; > > [[NSNotificationCenter defaultCenter] addObserver:self > > selector:@selector(buttonClicked) name:@"ButtonClicked" object:nil]; > > } > > return self; > > } > > > This also suggests you've embodied your model (mydata) in a view. It's one > reason you're resorting to using notifications to perform basic messaging - > nobody is really clear about their correct role here. > > If you can separate your design into clearly defined model, view and > controller layers, things will be far easier. Notifications have a useful > part to play but you're abusing them here in order to band-aid a muddled > design. > > General documentation about MVC should be a vital read at this point. > > --Graham > > > -- http://ericd.net Interactive design and development _______________________________________________ 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