• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Datasource for tableview and more
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Datasource for tableview and more


  • Subject: Re: Datasource for tableview and more
  • From: "Mark's Studio" <email@hidden>
  • Date: Sat, 1 Sep 2001 22:51:49 +0200

Thanks
On lxrdag, september 1, 2001, at 10:05 , Andrew Abernathy wrote:

>> Is it possible for one controller class be the datasource for multiply
>> tableviews?
>
> Sure. The datasource methods include the tableview as an argument. Your
> controller object should have outlets for the various tableviews, then
> the datasource methods should compare the passed in tableview with the
> outlets to see what to do.
>
> - (int)numberOfRowsInTableView:(NSTableView *)tableView;
> {
> if (tableView == addressGroupsTableView)
> return [addressGroups count];
>
> else if (tableView == addressesTableView)
> return [[currentAddressGroup addresses] count];
>
> // should never get here
> NSAssert3(TRUE, @" %@ %s - unrecognized tableView %p", [self
> class], _cmd, tableView);
> return 0;
> }
Yes i should have seen that one (NSTableView *)tableView
>
>> to be honest i don't understand the documentation on ObjC, all that
>> sharedInstance and stuff like that,
>
> The idea on a shared instance is that there is one main instance of the
> object in question, possibly only one instance total. It really doesn't
> have anything to do with Obj-C, or even Cocoa. Shared instances happen
> to be a common pattern in Cocoa development, but you will find them
> elsewhere.
>
>
> It sounds to me like you want a shared GroupController, but your
> document needs to be able to access the groups, and the way you're
> thinking of attacking this is with a shared instance of the group
> controller. (Perfectly fine implementation decision.)
>
> Your GroupController would need to 1) keep track of the shared
> instance, and 2) provide a way for clients to get it. That can be done
> like the following:
>
> @implementation GroupController
>
> + (id)sharedInstance;
> {
> static GroupController *sharedInstance = nil;
>
> if (sharedInstance == nil) {
> sharedInstance = [[GroupController alloc] init];
> }
>
> return sharedInstance;
> }
>
> [...]
>
> @end
>
>
> Then whenever a client (MyDocument in your case) needs that shared
> instance, it merely asks for it:
>
> groupController = [GroupController sharedInstance];
>
Does it work like this


In MyDocument

if i want to access something from the GroupController

groupController = [GroupController sharedInstance];

[groupController anythingInGroupController]
or just
[GroupController anythingInGroupController]

and do i need to declare everything with a + sign that i want to access

so if i want to Archive the NSMutableArray *GroupDB in MyDocument but
that is declared in GroupController

i have to do this in GroupController

+ (NSMutableArray *)GroupDB {
return GroupDB;
}

and then this in MyDocument i can do this

[NSArchiver archivedDataWithRootObject:[GroupController GroupDB]];

if i wanted






Original method from GroupController

- (IBAction)SelectedInGroupView:(id)sender
{
Group *aGroup;
int index = [GroupView selectedRow];
if(index > -1 && index <=[GroupDB count])
{
[GroupView selectRow:index byExtendingSelection:NO];
aGroup = [GroupDB objectAtIndex:index];
selectedGroupName =[aGroup groupName];
selectedGroupColor = [aGroup groupColor];
}

}

if i make a method in MyDocument


- (void)SelectionDidChangeInGroupView:
{
Group *aGroup;
int index = [GroupView selectedRow];
if(index > -1 && index <=[[GroupController GroupDB] count])
{
[GroupView selectRow:index byExtendingSelection:NO];
aGroup = [[GroupController GroupDB] objectAtIndex:index];
selectedGroupName =[aGroup groupName];
selectedGroupColor = [aGroup groupColor];
}

}
is it something like that



>
> -andrew
Peter Mark

Mark's Recording Studio A/S
Faelledvej 19 b DK2200 N
Copenhagen Denmark
Tel: +45 35366078 Fax: +45 35366038
www.marks-studio.dk
email@hidden


  • Follow-Ups:
    • Re: Datasource for tableview and more
      • From: Brendan Younger <email@hidden>
  • Prev by Date: Re: NSView requisites in java documentation
  • Next by Date: Higher-quality scaling of NSImages?
  • Previous by thread: Datasource for tableview and more
  • Next by thread: Re: Datasource for tableview and more
  • Index(es):
    • Date
    • Thread