Re: Help with creating CustomViews
You're on the right track with NSViewController. Make an NSViewController and a XIB specifically for this view controller. Set the -view outlet in your NIB and make sure you name the File's Owner the same as your NSViewController subclass. Make sure your initializer mentions the name of the correct XIB it requires. Then, in the rest of your code, instantiate your NSViewController subclass and ask for its NSView via the -view accessor. Add the NSView anywhere you want. I often do this by using an NSBox and using -setContentView: -Steven On Fri, Feb 19, 2010 at 4:20 PM, Jean-Henri Duteau wrote: > > On 2010-02-19, at 6:55 AM, Steven Degutis wrote: > > > It sounds a lot to me (and I could be wrong here) that you're trying to > implement something along the lines of an ActiveX control as they were back > when I used Visual Basic 5, in the sense that you want a "control" which is > really a collection of other controls, and to be able to drag them around in > IB and treat this collection as if they were a single control. > > > That's exactly what I want - a "control" which can be dragged around in IB > and, more importantly, created a number of times. I want View that I can > place on a window (or anywhere in IB) along a view controller. I can then > point the controller at the model and everything will "just work". > > > > What you're doing can easily be accomplished in code, by having an > NSViewController that points to your own XIB file, and by creating instances > of this view controller and inserting its view into other views. This is the > canonical way. Not only do you get more flexibility by doing it in code (and > a lot less repetition in IB) but this method allows you to encapsulate > another level of abstractness inside your NSViewController subclass, thus > cleaning up your code (a lot). This is what more experienced Cocoa coders > generally do instead of what you're trying to do. > > > I'm sure that it can and that's exactly what my first try did - I have a > custom NSViewController that points to my view's XIB file. I then added an > instance of my view controller. The problem is that I'm stuck from there - > I'm unsure how to get the view to appear where I want it to on the window. > I've added a Custom View in the layout and set its class to my view's > class. I attach the view to the view controller. And nothing happens and > I'm unsure what to override or call to make it happen. > > Jean___ > > 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/steven.degutis%40gmail.com > > This email sent to steven.degu...@gmail.com > -- Steven Degutis http://www.thoughtfultree.com/ http://www.degutis.org/ ___ 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
Re: Help with creating CustomViews
On 2010-02-19, at 6:55 AM, Steven Degutis wrote: > It sounds a lot to me (and I could be wrong here) that you're trying to > implement something along the lines of an ActiveX control as they were back > when I used Visual Basic 5, in the sense that you want a "control" which is > really a collection of other controls, and to be able to drag them around in > IB and treat this collection as if they were a single control. > That's exactly what I want - a "control" which can be dragged around in IB and, more importantly, created a number of times. I want View that I can place on a window (or anywhere in IB) along a view controller. I can then point the controller at the model and everything will "just work". > What you're doing can easily be accomplished in code, by having an > NSViewController that points to your own XIB file, and by creating instances > of this view controller and inserting its view into other views. This is the > canonical way. Not only do you get more flexibility by doing it in code (and > a lot less repetition in IB) but this method allows you to encapsulate > another level of abstractness inside your NSViewController subclass, thus > cleaning up your code (a lot). This is what more experienced Cocoa coders > generally do instead of what you're trying to do. > I'm sure that it can and that's exactly what my first try did - I have a custom NSViewController that points to my view's XIB file. I then added an instance of my view controller. The problem is that I'm stuck from there - I'm unsure how to get the view to appear where I want it to on the window. I've added a Custom View in the layout and set its class to my view's class. I attach the view to the view controller. And nothing happens and I'm unsure what to override or call to make it happen. Jean___ 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
Re: Help with creating CustomViews
It sounds a lot to me (and I could be wrong here) that you're trying to implement something along the lines of an ActiveX control as they were back when I used Visual Basic 5, in the sense that you want a "control" which is really a collection of other controls, and to be able to drag them around in IB and treat this collection as if they were a single control. While it is possible using IB Plugins, that's not really what IB's plugin system was intended for. This plugin system was meant more for control that are actually custom, such as a WebView object or PDFView or IKImageView or ABPeoplePickerView. (These are all custom classes which Apple has included into IB via its own default set of plugins.) This is to say, the plugin system is intended for actual subclasses of NSView or NSControl (or NSCell) which implement very specific and unique behavior, and where it's important (or at least desired by management) to be able to set their settings in IB during design-time. What you're doing can easily be accomplished in code, by having an NSViewController that points to your own XIB file, and by creating instances of this view controller and inserting its view into other views. This is the canonical way. Not only do you get more flexibility by doing it in code (and a lot less repetition in IB) but this method allows you to encapsulate another level of abstractness inside your NSViewController subclass, thus cleaning up your code (a lot). This is what more experienced Cocoa coders generally do instead of what you're trying to do. -Steven On Mon, Feb 15, 2010 at 9:19 PM, Jean-Henri Duteau wrote: > Hi all, > > I'm a newcomer when it comes to Cocoa development. I have some good books > and they discuss the possibility of CustomViews but the views they create > aren't the type that I'm interested. I've scoured the web and haven't found > exactly the help I need and I've tried the trial-and-error method and it > hasn't worked. > > What I'm trying to do is the following: > -I have a number of model objects, different instances of the same class. > -I want to create a CustomView that would enable the display of these > objects. > -The CustomView is defined in its own NIB file. It consists of a bunch of > NSTextField objects laid out in NSBox. > -I then want to use that CustomView all over the place. :) But for > starters, I'm trying to create a window with 10 instances of my CustomView. > -I want to drop the CustomView in other NIB files and set up the > actions/outlets/etc. > > The path that I took that seemed to give the best promise was: > I created a CustomViewController (subclassing NSViewController) > In MyDocument.init, I init the CustomViewController with my CustomView NIB > file. > In MyDocument.windowControllerDidLoadNib, I call viewController.view > setFrame: and then windowController.window.contentView addSubView. > > That manages to get my CustomView to show up in the document's window. But > that was done programatically and not in IB. > > Then I looked at the DragAround sample code on the Apple site. This seemed > to be exactly give tips for exactly what I wanted, except that the > DragAroundView draws itself, there is no NIB file for the view. > > If someone can point me to some sample code, that would be great. In the > meantime, I'll keep trying. > > Jean Duteau > > ___ > > 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/steven.degutis%40gmail.com > > This email sent to steven.degu...@gmail.com > -- Steven Degutis http://www.thoughtfultree.com/ http://www.degutis.org/ ___ 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
Help with creating CustomViews
Hi all, I'm a newcomer when it comes to Cocoa development. I have some good books and they discuss the possibility of CustomViews but the views they create aren't the type that I'm interested. I've scoured the web and haven't found exactly the help I need and I've tried the trial-and-error method and it hasn't worked. What I'm trying to do is the following: -I have a number of model objects, different instances of the same class. -I want to create a CustomView that would enable the display of these objects. -The CustomView is defined in its own NIB file. It consists of a bunch of NSTextField objects laid out in NSBox. -I then want to use that CustomView all over the place. :) But for starters, I'm trying to create a window with 10 instances of my CustomView. -I want to drop the CustomView in other NIB files and set up the actions/outlets/etc. The path that I took that seemed to give the best promise was: I created a CustomViewController (subclassing NSViewController) In MyDocument.init, I init the CustomViewController with my CustomView NIB file. In MyDocument.windowControllerDidLoadNib, I call viewController.view setFrame: and then windowController.window.contentView addSubView. That manages to get my CustomView to show up in the document's window. But that was done programatically and not in IB. Then I looked at the DragAround sample code on the Apple site. This seemed to be exactly give tips for exactly what I wanted, except that the DragAroundView draws itself, there is no NIB file for the view. If someone can point me to some sample code, that would be great. In the meantime, I'll keep trying. Jean Duteau ___ 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