Open fappelman opened 9 years ago
This is kind of tricky, and it touches on an edge case of MotionKit that I’m not pleased with: Cells (in iOS, in OSX there are also Prototypes like you are using) do not have a corresponding “Controller” where the Layout can live.
You can use a pattern that people have used to work with UITableViewCells. Assign the layout to the view, and assign the view as the root
layout object.
def loadView
view = MailView.alloc.initWithFrame([[0,0],[400,340]])
view.layout = MailViewLayout.new(root: view) # add and style subviews here
self.setView(view)
end
I’ve considered a change to the MotionKit::Layout class so that it is actually a subview of NSView
(UIView
on iOS). We would also provide subclasses of common classes, like MotionKit::TableViewCell
. This would break compatibility, though, so don't expect this soon..
If we implement the Layout < NSView
refactor, this would be easier:
class MailView < MK::View
def layout # as usual
end
I will try what you proposed. Appreciate the answer and you have my vote to refactor this to a view.
I have been using MotionKit and I have run into a problem which I cannot solve. I am trying to develop and OSX application.
The issue here is that I would like to create a new class that inherits from
NSView
using MotionKit as the layout engine.I have worked through the various samples and I have created the first outline of the UI which works great. So far so good.
In the application I use an
NSCollectionView
which has to be provided a prototype. In this case the prototype is a class namedMailViewPrototype
.The class itself is straight forward:
and the simplified version of the
MailView
class is this:I would like to use MotionKit for this class as well. I created the classed
MailViewLayout
andMailViewController
to control this.From here I run into a wall. The difference with the demo apps is here that this
NSView
needs to be created and I have no clue how to create aMailView
class that would use my newMailViewController
. My knowledge about Cocoa is limited so there is a good chance that my question is not MotionKit specific but any hint would be appreciated.