How can I use SplitView having TableViewControllers in Master and Detail parts - core-data

I am trying to use SplitView in order to show the information about employees. There is a list of departments in the Master part. The list of employers working in the chosen department needs to be shown in the Detail when clicking on the department.
I am using CoreData with two Entities: "Department" and "Employee" that are connected with “to-many” relation.
How should I do it?
Thanks

This is a simplified overview, since you asked a very broad question.
Create a UITableViewController subclass to be your Master view. It should have a property of type NSManagedObjectContext, and it should handle fetching and displaying the departments. (You could fetch them in loadView, or you could use an NSFetchedResultsController…)
Create another UITableViewController subclass to be your detail view. Give it a property of type NSManagedObjectContext, and also a property of type Department. Make it display the employees for that department. You'll want to make it reload its data whenever the department property changes.
Add a property to your master view controller, to refer to the detail view controller (so a property of type EmployeeViewController, or whatever you called it). Then in tableView:didSelectRowAtIndexPath: in your master view controller, set self.employeeViewController.department = <selected department>.
Create the split view controller. If this is the top level view of your application, you'll want to create it in your app delegate, otherwise create it in the view controller that pushes it to the stack. Here's how to do it (in pseudocode):
Create a new detail view controller
Set its managedObjectContext property
Create a new master view controller
Set its managedObjectContext property
Set the master view controller's employeeViewController property to your detail view controller
Create a new split view controller
Set the split view controller's viewControllers property to an array containing your master and detail view controllers
Get the split view controller on the screen somehow, either by pushing it onto the navigation stack or setting it as your root view controller in applicationDidFinishLaunching:.

Related

best way to pass core data values

Im developing a golf score recording app with three view controllers.
The first view controller is a table view controller that has each round that you play via an add round button. When you click a golf round(cell) it takes you to a new view controller that has 18 buttons correlating to each hole of that round. When you click on a hole button (i.e. Hole 1), it then pushes you to a new 3rd view controller where you can record values such as the Par of that hole, the yardage, and then also text fields to input each players score(all this being stored via core data).
Here is my dilemma. Im using core data to persist all the data. Im curious on what the best way to populate text labels on my 3rd view controller with information from my first view controller. Right now I am using the prepareForSegue function to create instances of the new view controllers and then setting the properties of the new view controllers via the prepareForSegue function.
This works just dandy. however, when i get to the third View controller i want to populate some of my fields with some of the data that corresponds to that round. And because the third VC is not a table view I'm lost at how to make sure its fetching the correct data from the correct corresponding indexPath. Right now I'm just passing values from the tableview through properties in the 2nd VC, and then passing those properties again to the 3rd VC. Is there a way i can just do a fetch request on a specific index path if I'm not on the tableview VC?
I hope that makes sense.
Your data structure probably looks something like this (or should):
Course (.rounds) <------>> Round (.course)
Round (.holes) <------>> Hole (.round)
You press on a row in the list of holes, simply pass the select Hole to the final view controller. If you need any information from any of the superordinate entities, simply use dot notation.
NSString *nameOfCourse = self.hole.round.course.name;
No need to fetch, no need to communicate with any other view controllers! How swell is that?

displaying a list on screen with orchard

Using orchard cms 1.6 I have a table in my db 'cars'. I want to display the column 'CarName' from the table, as a list on screen with all the records from the table.
carname1
carname2
carname3
When the user clicks on their link it will bring them to that page.
I know how to do this from the view e.g.
#T("Cars")
but I would like to try and create a content type which shows this list.
Content type seems to be all UI related. Im not sure how to take a table and display a column as a list on screen through the content type...any idea on how to do this?
then I can choose to show the content type as a form and the user can view it from the main menu.
thanks
It looks like you want to create a content type called Car, possibly with a CarPart and a record class CarPartRecord (perhaps refactor your Car class to CarPartRecord to follow Orchard's naming conventions). Make sure CarPartRecord derives from ContentPartRecord.
To render a list of Cars, you could use a Projection that renders a list of cars. A Projection renders content based on a Query, which you configure using the dashboard.
Alternatively, you could create a controller that leverages IContentManager to query all Car content items, and returns a view to render them in a table.
For each Car content item, use Html.ItemDisplayLink to render a link to its details page.

Can you pass a TreeController between views?

I have a standard Master-Detail Interface and I'm using Coredata and cocoa bindings.
The Master list uses a NSOutlineView and a NSTreeController, these items remain static but different details views are swapped in and out.
So, how do I set the content of the array controllers in the different detail views to correspond to the selection in the outlineview in the Masterview?
This is straight forward if all the array/treecontrollers are in the same .xib file. initially, I tried creating an Outlet from of the Treecontroller and passing this to the orther views as they are created, but I don't think this is correct.
Any suggestions?
You can use an array controller or a tree controller for as many views as you like. In your specific example, I would make the masterview owner of the tree-controller (unless you have a compelling reason to go yet another level up). Then each detail view that gets swapped-in would also have view controllers. That controller would have an assignable "tree-controller" property that would get set before its view is loaded to the value of the "master" tree-controller. Within the Nib files you can use bindings (to the tree-controller of files-owner) as you normally would.

Global sidebar with widget support

I would like to make a layout with a sidebar that can have widgets from different modules. Lets say there shall always be a login widget at the top if the user isn't logged in then it shall show user info. The getting started album guide could use it to display the latest albums and so on, i hope you understand how i want to use the sidebar.
Could it be done with a config file in autoload and a small code that read that config and calls the widgets on every page load?
There are several ways of page composition in Zend Framework 2:
1. Switching between Layouts
By default, ZF2 provides you with a single layout template layout.phtml.
In real-life applications, you will probably need to have several layouts
and switch the layout for certain controller/action. In each of your layouts, you will be able to show different widgets/sidebars.
2. Partial Views
A partial view is a .phtml view template file which can be rendered by another
view template. Partial views allow to compose your page of pieces and reuse pieces
of view rendering logic across different view templates. This is accomplished through the Partial view helper.
3. Placeholder View Helper
The Placeholder is another useful view helper allowing for capturing HTML
content and storing it for later use. Thus, analogous to the Partial
view helper, it allows to compose your page of several pieces.
4. Forward Controller Plugin
With the Forward controller plugin, you are able to call an action (for example, the action rendering some widget) from another module/controller from your controller and grab the output of that action. Then you are able to incorporate that output into your page.
5. Use View Models for Page Composition
When you write action methods for the controller classes, you use the ViewModel
class as a variable container for passing the variables from controller to view template,
and for overriding the default view template name. But, actually the ViewModel class is more than just a variable container plus view template name. In fact, it is closely related to the layout and page composition.
The third big capability of the view model class is that it allows for combining several
view models in a tree-like structure. Each view model in the tree has the associated
view template name and data variables that can be passed to the view template to control
the process of rendering.
This feature is internally used by Zend Framework 2 when "combining" the layout view template and the view template associated with the controller's action method. ZF2 internally creates the view model for the layout template and assigns it with layout/layout view template name. When your controller's action method returns the ViewModel object, this object is attached as a child to the layout view model.
So, you can attach your own view models to the default view model to render the page of pieces that you want.

Updating an AnnotationView Callout after details entered in View Controller that was pushed form the map view

I have a simple maps app with multiple pins on a map view. My intention is to tap a pin, show a callout with an accessory view, push to a Detail View Controller where you can edit that pin/locations details. This all works fine, but once i pop the Detail View Controller the callout on the map view is still there, which i want, but it still has the old uneditied values. How can i refresh/update the callout view once the Detail View Controller is popped?
I am using Core Data with a simple database. I have tried using controllerdidchangecontent, Map View Controller Will Display methods etc but my main problem is identifying which object has been added/updated/deleted and which is the corresponding callout/selected pin.
Any help appreciated...
Not sure if you had find your answer but the way to do it is to extend MKAnnotation class and creating custom annotation and passing them while creating placemarks. Later you can get them from MKAnnotationView's annotation property.
See a good implementation here
http://www.slideshare.net/360conferences/getting-oriented-with-mapkit-everything-you-need-to-get-started-with-the-new-mapping-framework
The only way I could find to update the callout info was to mess directly with the subviews of the callout.
The callout view is the first subview of the annotation view.
In the following example, I update the subtitle.The title label is the 6th and the subtitle is the 7th subview of the callout:
if (myAnnotationView.subviews.count > 0)
((UILabel*)[((UIView*)[myAnnotationView.subviews objectAtIndex:0]).subviews objectAtIndex:7]).text = #"Some example";

Resources