Call IBAction in different class?

If your sheet is a nib/xib with an NSPanel, the call to close it is simply panel close; Assuming your window controller has a property for the panel, you can put the close code at the end of its row-adding IBAction. Or you could have the IBAction itself call another method if you prefer If your panel is running modal, you might need to stopModal too. (That's what's needed if everything stays frozen after the panel closes; otherwise never mind.) Assuming hopBill, your data source, is a property of the window controller, any IBAction you write in the window controller also has access to hopBill; it can do everything you need So add a single IBAction to the window controller and connect the panel's OK button to it.

That ought to work As for calling an IBAction from somewhere other than a control in a nib, yes, you can do that. Use a reference to the control as the sender arg, or nil if the IBAction doesn't use the sender arg You could also create your panel programmatically, or use NSAlert. But it sounds like your current setup is simpler -- and therefore better Take a look at this h file for an app controller: Apple's ClockControl example The NSMutableArray *appointments property is the actual data source that will be used by the NSTableViewDataSource protocol methods.

The IBAction "addAppointment" can access "appointments" directly: self. Appointments addObject:whatever atIndex:whatever The ClockControl example could be modified to use HopBill. You would import its declarations up top: #import "HopBill.

H" And then instead of the "appointments" property, it would declare HopBill *hopBill; And "addApointment" would access HopBill's mutable array (aHopBill) like this: self.hopBill. AHopBill addObject:whatever atIndex:whatever.

If your sheet is a nib/xib with an NSPanel, the call to close it is simply panel close; Assuming your window controller has a property for the panel, you can put the close code at the end of its row-adding IBAction. Or you could have the IBAction itself call another method if you prefer. If your panel is running modal, you might need to stopModal too.(That's what's needed if everything stays frozen after the panel closes; otherwise never mind.) Assuming hopBill, your data source, is a property of the window controller, any IBAction you write in the window controller also has access to hopBill; it can do everything you need.

So add a single IBAction to the window controller and connect the panel's OK button to it. That ought to work.As for calling an IBAction from somewhere other than a control in a nib, yes, you can do that. Use a reference to the control as the sender arg, or nil if the IBAction doesn't use the sender arg.

You could also create your panel programmatically, or use NSAlert. But it sounds like your current setup is simpler -- and therefore better. Take a look at this h file for an app controller: Apple's ClockControl example The NSMutableArray *appointments property is the actual data source that will be used by the NSTableViewDataSource protocol methods.

The IBAction "addAppointment" can access "appointments" directly: self. Appointments addObject:whatever atIndex:whatever; The ClockControl example could be modified to use HopBill. You would import its declarations up top: #import "HopBill.

H" And then instead of the "appointments" property, it would declare HopBill *hopBill; And "addApointment" would access HopBill's mutable array (aHopBill) like this: self.hopBill. AHopBill addObject:whatever atIndex:whatever.

Thanks for your answer. The NSPanel runs as modal and is a different object than the hopBill my datasource. That's why I haven't got access to hopBill.

I need to perform two action on two different objects, adding a record to my datasource and closing the window. Or is it best practice to make one object out of the datasource object and the modal window object? – Joran Jun 10 at 21:15 Right, the NSPanel has to be a different object from the data source.

Both the panel and HopBill would normally be properties of your window controller. I've added to my answer an example that might make the structure more clear. You might also want to consult an Objective-C or Cocoa programming book for some complete tutorials.It's hard to understand this stuff just by discussion.

– Wienke Jun 11 at 0:16 Thanks for your answer. I can't seem to get it to work. I added #import HopBill.

H to HopBillSheetController.h. And inserted the code you mentioned in HopBillSheetController.m. But on Build I get an error on the self.hopBill.

AHopBill line stating "Request for member 'hopBill' in something not a structure or union". Maybe I'm doing something completely wrong, that why I uploaded the source to: kloran.home. Xs4all.

Nl/iBrouwsrc.zip. I've got the books Objective-C for Dummies and Cocoa Programming for Mac OS X for Dummies. – Joran Jun 11 at 11:06 The xib holding your main window and panel has a file owner of type MyDocument, which is a subclass of NSDocument.

I have never worked with NSDocument, which, looking at Apple’s “Documents-Based Applications Overview,” has a special architecture unto itself. So I can’t help much there — although I suspect you’ll need to move your IBActions to whatever ends up as your top-level controller, probably MyDocument. And MyDocument should probably have a property that is an instance of HopBillSheetController.

Dot syntax, as in self.hopBill. AHopBill, won’t work without @property and @synthesize lines. – Wienke Jun 11 at 13:59 Apologies: I failed to note that your question starts out with "My document based application..." That should have clued me in to the fact that your app's structure is different from what I'm used to.

(I added an NSDocument tag to your question. That might bring in better help.) – Wienke Jun 11 at 14:14.

Why you can’t send messages to hopBill: First, because although you declare it, you never initialize it. You have: HopBill *hopBill; self.hopBill. AHopBill addObject: bHopAdditionAtInit; It should be: HopBill *hopBill = HopBill alloc init; hopBill.

AHopBill addObject: bHopAdditionAtInit; // “self” won’t work here Second, you’re declaring it inside an IBAction method, (doneHopBillSheet:), so it’s a local variable, accessible only within that method. If HopBill is holding your table’s data source cache, it should be a property of the controller which implements the NSTableViewDataSourceProtocol methods. In your HopBill interface, you declare the aHopBill array to be a property, and you initialize it in HopBill’s init method (you should also release it in HopBill’s dealloc method).

You need to do the same thing for the controller — it should have an instance of HopBill as a property, and that instance should be initialized in the controller’s init method. If you want HopBillController to manage the tableview, its interface declaration should look like this: @interface HopBillSheetController : NSWindowController { … } And, then, of course, you have to implement the relevant NSTableViewDelegate and NSTableViewDataSource methods. Also, the controller must have an IBOutlet property for the tableview itself, and in the controller’s awakeFromNib method, it has to assign itself as delegate and datasource: self.

Tableview setDelegate:self; self. Tableview setDataSource:self; (The self-dot syntax assumes you’ve set up @property and @synthesize code for tableview. ) The IBAction method that adds items to your table must be in that controller class, or in a class that has a property which is an instance of the controller class.

Then the IBAction method will have access to the aHopBill array and can add the new object to the array, after which it will call tableView reloadData, which will in turn trigger the tableview protocol methods and update the table. Now, that means that the xib containing the tableview has to have the controller as its file’s owner. Since you’re using NSDocument, I suspect that, instead, you would put the tableview outlet in the NSDocument subclass.

And you would give that doc subclass a property which is an instance of the controller. The IBAction methods would also be in the doc subclass, and so they would have access to the controller and its HopBill property. Or maybe you would simply make the doc subclass the controller, rather than using the separate HopBillSheetController class.

I’m not sure about the NSDocument stuff. But, remember, the IBAction method can itself call other methods, as long as it has access to instances of the classes in which those methods are declared. Apple has an example using both the tableview delegate and datasource protocol methods.

Go to this link and download the sample code: tableview example It looks like a nice app. Good luck.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions