I chose page-based layout for my WatchKit app. Each page shows a table. I want to keep the layout of the table exactly the same across all pages. I will be feeding filtered data to each page at run time, so essentially pages will be identical, except the data will be different.
One way to achieve this is to manually create InterfaceController instance for each page in InterfaceBuilder, then populate with GUI elements and connect the outlets. The problem here is whenever I want to change something (say, move a label or add a button), I will have to apply that change consistently to every page.
Moreover, for each page I have to connect the outlets to table row controller, essentially repeating myself over and over again. Here's an illustration:
Is there a way to reuse a table?
I considered inheritance, but the documentation tells me not to subclass WKInterfaceTable. This also rules out creating a table programmatically.
You should create a single interface controller with the table and various row types. Then you want to create an architecture very similar to my answer here. You'll only have a single PageOneInterfaceController which should be named TableInterfaceController in this example with TableInterfaceIdentifier as the identifier. Then you would do the following:
MainInterfaceController.swift
func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
let context1 = "context 1 - for you to fill out"
let context2 = "context 2 - for you to fill out"
let context3 = "context 3 - for you to fill out"
WKInterfaceController.reloadRootControllersWithNames(
["TableInterfaceIdentifier", "TableInterfaceIdentifier", "TableInterfaceIdentifier"],
contexts: [context1, context2, context3]
)
}
This will reload the page set using the same interface controller that displays all the data in the respective context.
To accomplish this, provide the same WKInterfaceController in reloadRootControllersWithNames:contexts: multiple times, but provide a different context to each one.
Related
(I'm using Prism Dryloc) My application consists of two views. The first contains a single list view displaying strings and the second - an entry and a button.
The listview is bound to an observable collection in the first page's View Model. How can I add to the observable collection from a different view?
Great question! You're essentially trying to pass data between views, and there's several ways of passing data between Views in Xamarin.Forms.
The two ways that seem relevant for your case:
Either making the ObservableCollection a public static object (so there's only one global instance of it). Not recommended.
The better way is to use the messaging center so that the second page publishes an event when the button is pressed, that the first page is subscribed to. And it passes that information that gets added to the list.
If these don't work, elaborate your use case and I'll suggest some more
I have created 2 content types; Episode which has actual episode information and Channel which has a channel description which includes a few fields specific to the channel plus an Entity Reference to Episodes.
While entering data, you can select "Add new episode" and are able to add as many episodes as you wish. The data is all visible and correct in View Content.
I need now to create a view which looks something like this:
Channel Name
Channel Info
Episodes:
Ep 1
Ep 1 content
Ep 2
Ep 2 content
etc.
I can create a view of Channels or a view of Episodes, just don't know how to integrate the one into the other.
Having the darndest time figuring out what I am doing wrong. perhaps it's as much about terminology as anything else as I come from a different CMS background. TIA
This can be achieved using the display suite module and linking the entities using a custom view mode, and then rendering a rendered entity in your view.
So Install the Display Suite Module.
Setup a custom View Mode, and enable the custom view in the "Parent" content type, and select single column layout.
Add the Entity Reference Field to your columns, and select rendered entity.
Then Create a new View, referencing the "Parent" Content Type, and the views output, select rendered entity and choose the custom view mode you created.
I was over-thinking the solution. In the Manage Display for the Channel, set Episodes to display as Rendered Entity. From that point, I was able to then modify the Manage Display for the Episode content type. This was all that was necessary.
im a osx-dev noob that is trying to build an application with three table views that will show the content of a core data store entity. But each table view is filtered on the attribute "status" of the entity.
the problem occurs when i also want to show the selected entity in textfields. I'm using three different array controllers with different fetch predicates. But in a textfield i can only bind the value to one array controller.
should i ditch the bindings and do it all programaticly or is there a simple solution to this? :)
here is an screenshot so you can grasp my app description.
Keep bindings to populate the text fields if it satisfies what you want to do with this GUI. I'd add an NSObjectController to control the one entity those fields represent. If you want the user's changes to those fields persisted, bindings are still awesome.
But I think with three tables that might control what's displayed in the text fields, you're going to need to have some sort of non-binding glue code that determines which of the tables wins. You can probably do everything you want by implementing some of the NSTableViewDelegate protocol.
If the text fields should display the last entity that the user clicked in any of the tables, simply have each table call the same tableViewSelectionDidChange delegate function. All three tables could have the same delegate. You can then call setContent on the NSObjectController from that function.
You could also use similar glue code to prevent more than one selection in any of the three tables, by having the same delegate function deselect everything in the other tables either through the view or the controller. But that's up to you and needs consideration of whether you want multiple selection, etc.
I'm trying to create a Mac OS Core Data application that has an array of parent objects (called Levels) each of which contains a collection of child objects (called Blocks) via a one-to-many relationship. I have a table view successfully controlling the array of levels, and a custom view object that draws the blocks graphically based on positions held in x and y properties of my Block model class. I can add blocks to the currently selected level, remove them, select and move them around in the custom view, and have bound text fields to various other properties of the Block class which I can use to edit those values. All of this information is successfully saved and restored to and from the core data repository with no issues output to the debugger. Wonderful. I've used an NSArrayController for the Levels and another for the Blocks that is bound to the current selection of the Levels array controller, in what I've read is a pretty standard way.
Now, my Block class is actually an abstract class, and what I actually instantiate are various child classes of Block (eg RedBlock, GreenBlock, BlueBlock classes). Each sub-class has a separate set of properties that only apply to that type of block (so RedBlock has a "text" property that none of the others have, BlueBlock has an integer "value" property, etc). I want to create an inspector that will change depending on the type of the Blocks that are currently selected in my custom view. To try this, before I start creating subviews for each type of Bock, I have created a text field that I want to bind to the currently selected RedBlock's "text" property, preferably showing nothing when Blocks of other kinds are selected. This is where I'm stuck. I've added another NSArrayController in Entity mode with RedBlock specified as it's type so I can bind to the "text" property, and tried adding a filter predicate based on the class type. I've also tried various other configurations and bindings, but I'm either getting exceptions, or corrupt values in the text field that I bind to that controller, or other weird bugs and general brokenness.
I've googled around for an example of an inspector that can cope with a heterogenous array of objects (as that's essentially what I'm trying to do) but so far no luck.
So, my question is - am I going about this the right way? Should I be trying to create an NSArrayController that filters the selected items in my Blocks array controller somehow? If so, should that be straightforward or is there some trick that I've missed? If not, what is the best way to do this?
This approach should work, provided you limit the inspector to displaying view which bind to properties which apply to the entire selection. You don't need a second array controller.
To test the simple example, try creating a data set with only blocks, see that your bound control loads without raising exceptions, and that it updates the object correctly.
Once that is working, create separate views for each type, and display and hide them when the selection will change. Again, if you have a heterogenous selection, hide them all.
This is my first time building a UI in Access (using Access 2007), and I'm wondering what is the Right Way (TM) of going about this.
Essentially, I have several different queries that I'd like to display as pivot charts, pivot tables, tables, and reports. Eventually I'm also going to have to build forms to manipulate the data as well, but the application's primary function is to display data.
I'm thinking of having a button for each different display down the left side of the main window, and having the rest of the window display each button's corresponding contents (e.g. a pivot chart).
I have an idea that this can be accomplished using a single subform in the main form, and setting the subform's Source Object property within a function such as this one:
Public Function SetSubformSourceObject(newSourceObject) As Variant
subform.SourceObject = newSourceObject
End Function
Then, for each button I'd set its OnClick property to call this function with the name of the query I'd like to run.
Now, I have no idea if this is the best way of going about things, and would really appreciate some input :)
The principle seems fair to me. You have to give it a try. You do not even need a form-subform structure. You can set your sourceObject at the form level, and have your buttons in a commandBar instead of having them as controls on the form, so you do not have any 'form specific' code (like "onCLick") and controls. action/command controls on a form are space, code and maintenance consuming, while commandbars are more generic and are THE object that can hold all your action controls.