How to implement NSTableView class using (MVC) archiciture? - cocoa

I want to implement MVC architicture in my project. So I have to implement NSObject class for NSTableView.But some delegate method is not called. How to implement this class? Please help me for this issue.

The Table View Programming Guide can teach you what you need to know.
The NSTableView class reference page lists some sample code for you to try out on your own

Related

Try to bind partial view for different classes

I try to use one partial view for all classes implementing particular interface
#{Html.RenderPartial("_PaymentItem", Model.RentItem);}
#{Html.RenderPartial("_PaymentItem", Model.EquipmentItem);}
#{Html.RenderPartial("_PaymentItem", Model.InterestItem);}
#{Html.RenderPartial("_PaymentItem", Model.ForfeitItem);}
#{Html.RenderPartial("_PaymentItem", Model.SupplyItem);}
All PaymentItems are part of the model. After I post the page all payment items bind the values from the last rendered partial view. I assume the problem is that the partial view generates same ids and names for each invoke. How can i bypass this ?
Thanks in advance, I'll appreciate any help.
Have you tried casting your model properties to the particular interface?
EDIT:
What I mean is to specify the model
e.g.
#model IViewM
on the first line of your _PaymentItem file.

MVC JavaFx methods

if I want to add for example the mouse event "setOnMouseEntered" to my code and I already have a viewer, controller, model and main. Where do I put this method in?
Because if I search for examples, this methos is written in the start-method. In my case it would be in the main class? Actually have kind of a scene styler in the viewer.
Thanks!
do you search for something like this?
https://github.com/StefanHeimberg/javafx8-spielwiese/tree/master/example-fullscreen-fade/src/main/java/example/menubar.
in the menubar.fxml (VIEW) i used the onAction="#handleImage2LongRunningAction" and fx:controller="example.menubar.MenubarPresenter" (CONTROLLER)
then on the presenter i called some service (MODEL / Business Logic)...

Change UILabel from appDelegate

I want to do some stuff from the appDelegate in Xcode. One of these things are to change a UILabel.
ViewController *viewController = [[UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"id"];
viewController.label.text = #"heeej";
I was told this would do the trick. Doesn't work. Label doesn't change. Does anyone know what the problem is?
There are several problems:
Don't do anything in the AppDelegate except for loading the window an the initial view controllers (if needed).
You are instantiating a new view controller in the first line. I assume you already have a view controller and you want to change the label in that view controller. Than you need a reference to that view controller and use this reference to send messages to it.
The label should not be a property of the view controller. You should try to follow the design pattern Model-View-Controller or the pattern Model-View-ViewModel. Ask you preferred search engine what those are if you don't know.
id as an identifier for anything in Objective-C is a bad idea because this is used as an object type.
Edit: You don't need a reference to change a property in the view controller. Use notifications to update the label. The system sends a notification with the name UIApplicationWillEnterForgroundNotification' (see [here][1]). Add the view controller as an observer to the[NSNotificationCenter defaultCenter]` for this name and react on the notification. Read the Apple documentation if you don't know what I am talking about.

Cocoa MVC restrictions

In Cocoa MVC adoption, View knows nothing about the Model, which illustrated in this diagram:
But consider this example:
I have Item class in my model and I want visual representation for it. Most obvious for me is ItemView class, which is initialized with Item.
So, in this way, I'm breaking Cocoa MVC rules and feeling uncomfortable with it. But, I'm feeling uncomfortable also not having class like ItemView. What is the most practical solution?
If you are really concerned about MVC, what about defining a method in your controller like:
- (UIView*)itemViewForItem:(Item*)item;
which is responsible for creating and "populating" your ItemView?
You main controller class would then act as a controller both for your main view and all ItemViews you have got.
Another approach would be giving each ItemView its own ItemViewController. This is perfectly fine and if your controller/view is of any complexity, IMO, also the best approach. The drawback with this is that dealing with controllers container is supported only on iOS>5.

iOS protocols and delegates. Basic questions

I'm creating an app that has a UITableView.
The data will be comming from an XML fetched over the net. I'm using NSXMLParser for this and it works. I used my tableView controller as the delegate for this so it implements the protocol for it:
#protocol NSXMLParserDelegate;
#interface MainView : UITableViewController <NSXMLParserDelegate>
Now this works perfectly, as I've nslogged the resulting parse.
Now, I want to populate the NStableView, so Reading I find that I need to add the datasource and delegate.
UITableViewDataSource
and
UITableViewDelegate
both of which are protocols.
How would I go about doing this on the same class? can I implement more than one protocol with the same class? should I move the delegation of the parser to another object and use this controller for this purpose?
Basically the question is what is the best way to do this?
thank you
Sure, you can implement as many protocols in a class as you want:
#interface MainView : UITableViewController <NSXMLParserDelegate, UITableViewDataSource, UITableViewDelegate>
Is that the "proper" way of doing that? I don't think there's a "right" answer to that. A purist might say no. I'd say do it where is makes sense, but err on the side of breaking it out into separate classes. For example, if your view controller is a simple menu then it would make sense for your view controller to also be your table view delegate and data source; there's no advantage in breaking it out into multiple classes.
If you have to parse XML my intuition suggests that it's starting to get a bit more complex. Maybe have a data class that implements the data source and XML parser and a controller class?

Resources