Re: Bindings
Re: Bindings
- Subject: Re: Bindings
- From: Sandro Noel <email@hidden>
- Date: Sun, 27 May 2007 16:21:47 -0400
Ok i figured it out ...
instead of assigning the array to my controller instead i made an
accessor to the BonjourScanner
and thru that accessor i can access the bserivesList ...
and it works fine ...
again .. than you all for the help ...
and sorry for being such a beginner :)
Sandro Noel
email@hidden
On 27-May-07, at 3:45 PM, Sandro Noel wrote:
k i figured out something....
first off .. thank you all for your help in getting me on the right
path with the bindings...
help is REALLY appreciated.
1:
My utility Class (BonjourScanner) uses NSNetServiceBrowser to get
the list of services on the network
then the services are stored in a NSMutableArray and can be
accessed with the accessor "bServicesList"
- (NSMutableArray *) bServicesList
{
return _bServices;
}
and this is managed by delegate methods, and is async. the process
returns imidiately...
when a service becomes available, it is added to the array and
deleted from the array when it is unavailable.
2:
My application controller created an instance of this class
"BonjourScanner", and assigns a reference to an internal variable
_bonjourServicesList
@interface iSyncTooController : NSObject
{
NSMutableArray *_bonjourServicesList;
BonjourScanner *_bonjourScanner;
}
---------------------------------------
- (id) init{
self = [super init];
if (self != nil) {
_bonjourScanner = [[BonjourScanner alloc] init];
_bonjourServicesList = [_bonjourScanner bServicesList];
}
return self;
}
My controller has the accesor to get the array
- (NSMutableArray *)bonjourServicesList{
return _bonjourServicesList;
}
the scan begins when the Action is triggered from the View.
- (IBAction)startScan:(id)sender
{
[_bonjourScanner searchForServices];
}
and the scan stops "if" the stop action is triggered
- (IBAction)stopScan:(id)sender
{
[_bonjourScanner stopSearch];
}
Now, the updates to the Array Happen automatically and
asynchronically inside the BonjourScanner Object.
I followed your advice and added the under-code in the
BonjourScanner class, in the delegate method when the array gets
updated with a new object. but that had no effect.
[self willChangeValueForKey:@"bServicesList"];
[_bServices addObject:aNetService];
[self didChangeValueForKey:@"bServicesList"];
so i tried putting will and did change into the start and stop scan
and it worked ... Ye!
- (IBAction)startScan:(id)sender
{
[self willChangeValueForKey:@"bonjourServicesList"];
[_bonjourScanner searchForServices];
}
- (IBAction)stopScan:(id)sender
{
[_bonjourScanner stopSearch];
[self didChangeValueForKey:@"bonjourServicesList"];
}
BUT now i still have a little problem, because in the final
application the Stop will most likely NEVER be called except when
the application quits... or if the user decodes to stop the active
scan....
any pointers ?
I was thinking on sending notification from BonjourScanner and
caching them in the controller...
is there a better way ?
Thanks a bunch!!
Sandro Noel
email@hidden
On 26-May-07, at 10:53 PM, I. Savant wrote:
Well, in all fairness, maybe I wasn't being clear (or rather,
precise).
If you have an object (say, a document) and it has an array
called _bServices with a controller bound to it via, say
"bServicesArrayAccessor", any changes you make directly to that
array (adding/removing) need to be enclosed in the appropriate
notifications:
[self willChangeValueForKey:@"bServicesArrayAccessor"];
[_bServices addObject:someObject];
[self didChangeValueForKey:@"bServicesArrayAccessor"];
This will cause anything bound to your document via the
bServicesArrayAccessor key to note the changes (in this case your
controller).
Alternatively you could simply tell your array controller to -
addObject:someObject which would let the array controller to
handle all the notifications, etc. for you. Either way will do.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden