Re: indexing of objects in a subview array SOLVED
Re: indexing of objects in a subview array SOLVED
- Subject: Re: indexing of objects in a subview array SOLVED
- From: Boyd Collier <email@hidden>
- Date: Thu, 11 May 2006 16:48:22 -0700
Mike et al.,
I feel like a complete knuckle-head! The problem was a ; after the if
statement, just before the break (see below). The light goes on,
albeit very slowly sometimes.
My sincere apologies for having wasted your time, and thanks again
for taking the trouble to respond.
Boyd
On May 10, 2006, at 3:39 PM, Mike Abdullah wrote:
OK, fair enough, although I stand by my point that it really
shouldn't ever matter to you at what index a subview is. To be
honest, NSView probably ought to use an NSSet instead.
However, looking at your code I can see no reason why you should be
encountering this, although I do have a couple of thoughts:
1. How many times have you tested each? There's no reason why the
loading of the nib may not be different each time
2. Are you sure that all your subviews don't have a tag of 15?
It's just the sort of mistake I might make, and it would certainly
explain the result!
Mike.
On 10 May 2006, at 19:05PM, Boyd Collier wrote:
Mike,
Yes, I realized this. What strikes me as strange, however, is that
the order appears to change when the contents of the nib are
exactly the same, both forms start with NSArray *subviewArray =
[ _groupsNibView subviews]; and the rest of my code (not shown) is
otherwise identical.
Thanks for taking the time to reply.
Boyd
On May 10, 2006, at 9:36 AM, Mike Abdullah wrote:
I don't think there's any guarantee about the ordering of
subviews in a view. They're just subviews, their order as such
shouldn't matter.
Mike.
On 10 May 2006, at 01:06AM, Boyd Collier wrote:
In attempting to better understand subviews, I tried two
alternative forms of what would seem to be doing the same thing
(see below). In the nib containing the subviews there are 6
items, and in code not shown, the 2 forms agree in this regard.
However, the first form indicates the item whose tag is 15 is
the last item in subviewArray (that is, i = 5), while the second
form indicates that this item is the first item in the array
(that is, i = 0). No other changes were made in my code, nor
was the nib file altered. Why would the ordering of objects in
subviewArray be different?
[Please understand that I'm just trying to understand what seems
to be an anomaly. I mention that to avoid anyone feeling they
need to scold me for not using an iterator or for looking at tags.]
Boyd
// FIRST FORM
NSArray *subviewArray = [ _groupsNibView subviews];
int i = [subviewArray count];
NSLog(@"number of items in groups subview = %i", i);
while (i)
{
i--;
if ( [[subviewArray objectAtIndex:i] tag] == 15);
break;
}
NSLog(@"the index of the object is %i", i);
// SECOND FORM
NSArray *subviewArray = [ _groupsNibView subviews];
NSLog(@"number of items in groups subview = %i",
[[ _groupsNibView subviews] count] );
int i = 0;
while (i < [subviewArray count])
{
if ( [[subviewArray objectAtIndex:i] tag] == 15);
break;
i++;
}
NSLog(@"the index of the object is %i", i);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden