Problem with CoreData and accessing relationships : request for member in something not a structure or union
I have a question regarding a rather advanced DataModel which I would like to use with CoreData.
Before I get into details about what I did so far, I will describe what I want to do.
I have a List of Hotel Guests that stay in one Room and have Preferences. Once ready the user should select a guest and see the data and should also be able to add new guest, select the room (maintained also by application) and select their preferences (where the user can also add new preferences). The guest can have no or many preferences.
So here is what I have so far. I created 3 Entities : - Rooms with roomnumber - Preferences with name - GuestInfo with name -> with these Relationships room (Destination Rooms) and prefs (Destination Preferences with "To-Many Relationship") The prefs is a NSSet when you create a Managed Object Class.
So far so good. Now I have a UITableViewController that displays all guests, when I click on a guest I have another UITableViewController showing the details(DetailsViewController). Clicking on the Preferences it will go to another UITableViewController where I can select the Preferences. The problem I have is when I want to actually access the prefs in the DetailsViewController. Here is my cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
开发者_开发技巧static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
switch (indexPath.row)
{
case 2:
cell.textLabel.text = @"Preferences";
NSEnumerator *e = [info.prefs objectEnumerator];
id collectionMemberObject;
while ( (collectionMemberObject = [e nextObject]) )
{
Preferences *prefInfo = collectionMemberObject;
DebugLog(@"===> %@", prefInfo.name);
}
break;
}
info is the GuestInfo I pass through to the DetailsViewController.
Now with this I do get "request for member in something not a structure or union" accessing prefInfo.name.
Any idea whats wrong ?
thx
I had the same problem, the solution is as simple as you will bang your head against the wall once you hear it ;)
try [prefInfo name] instead of prefInfo.name.
精彩评论