Re: KVC Question
Re: KVC Question
- Subject: Re: KVC Question
- From: Nathan Kinsinger <email@hidden>
- Date: Fri, 10 Oct 2008 04:12:20 -0600
On Oct 9, 2008, at 8:04 PM, Joseph Crawford wrote:
The issue I am running into is that when I run a search only the
first row in the table view is populated with data from my results
array. I am thinking this is because the valueForKey method is not
passed the row index so it does not know which result object to
return.
I have the model key path for my first name column set to
primaryPerson.firstName, this is calling the primaryPerson method
which returns an instance of the person object. Then it will use
the value of the firstName property to populate the table column.
The problem is with the following in CBSManagingViewController:
- (CBSPerson *)primaryPerson
{
// This will loop over all objects in the result people
array and find the primary person
// IB will bind to this method to get at the data for the
table view
// arrangedObject.primaryPerson.firstName
NSMutableArray *res = [self results];
if( [res count] > 0 )
{
for(CBSSearchNameResult *result in res)
{
NSMutableArray *people = [result people];
if( [people count] > 0)
{
for(CBSPerson *person in people)
{
if([[person rank]
isEqualToString:@"primary"])
{
return person;
}
}
}
}
}
}
This will only ever return the first primary person of the first
result. Every time it is called it will start over and again return
the first primary person of the first result. Note that the return
statement will jump out of the routine immediately and the rest of the
iterations of the loops will never execute.
You need to move the primaryPerson: (and primaryPhone:) logic out of
the CBSManagingViewController and into the CBSSearchNameResult class.
You just need the part above where it starts with: "for(CBSPerson
*person in people)".
On a side note, you don't need to check the count of the arrays before
each for-in loop, if the array is empty the loop will skip over it's
code.
Given that the tableview is showing the one row, and your
primaryPerson: method is in the controller, I'm guessing that you set
the NSArrayController's binding to the CBSManagingViewController
itself. You need to bind to the results array of
CBSManagingViewController. If the view controller is File's Owner then
the binding for the content array should be:
Bind to: File's Owner
Model Key Path: results
Or you can go the tableview data source route and get rid of the
existing bindings. Just make sure to bind the dataSource outlet of the
tableview to File's Owner.
--Nathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
References: | |
| >KVC Question (From: Joseph Crawford <email@hidden>) |