Search code examples
iosobjective-cipaduitableviewuisplitviewcontroller

The detail view on my iPad storyboard is not getting populated


There are a million questions on Stack Overflow about this but none are working for me.

My app works fine for iPhone. I have a tableView and when I segue, the data moves fine.

For the iPad, I am not getting the detail data in a splitView. But when I log the detailView object, I see the following:

2014-08-28 17:44:26.298 GuessGreek[59754:607] -[WordViewController tableView:didSelectRowAtIndexPath:]
2014-08-28 17:44:26.299 GuessGreek[59754:607] -[WordDetailsViewController viewDidLoad]
2014-08-28 17:44:26.300 GuessGreek[59754:607] detailItem 1<WordEntity: 0x786853e0> (entity: WordEntity; id: 0x78685810 <x-coredata://B2B61C41-1855-46EB-AA5E-04697CA6B025/WordEntity/p1454> ; data: {
    category = uncategorized;
    changeFlag = nil;
    englishScore = 0;
    englishText = "unmarried, single";
    example = nil;
    favorite = nil;
    greekScore = 0;
    greekText = "\U03ac\U03b3\U03b1\U03bc\U03bf\U03c2-\U03b7-\U03bf";
    type = Adjective;
    uid = 1454;
})

2014-08-28 17:44:26.302 GuessGreek[59754:607] 1 greekTextField: (null)
2014-08-28 17:44:26.303 GuessGreek[59754:607] 1 englishTextField: (null)

The detail object looks populated but when I log individual components, they are blank.

My code for this is as follows:

WordView

iPad:

> -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
>     if (_IPAD) {
>     
>         id object;
>         if (self.searchResults.count > 0)
>         {
>             object = [self.searchResults objectAtIndex:indexPath.row];
>             [self.searchDisplayController setActive:NO];
>         }
>         else
>         {
>             object = [self.fetchedResultsController objectAtIndexPath:indexPath];
>             
>         }
>         
>         wordDetailsViewController.detailItem = object;
>         [wordDetailsViewController viewDidLoad];
>        
>     } }

iPhone:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"wordToDetails"])
  
        NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView indexPathForCell:(UITableViewCell *)sender];
    
        id object;
        if (indexPath != nil)
        {
            object = [self.searchResults objectAtIndex:indexPath.row];
            [self.searchDisplayController setActive:NO];
        }
        else
        {
            indexPath = [self.wordTable indexPathForCell:(UITableViewCell *)sender];
            object = [self.fetchedResultsController objectAtIndexPath:indexPath];
          
        }
        
   
        WordDetailsViewController *destinationController = segue.destinationViewController;
        
        destinationController.detailItem = object;
        
   }
}

DetailView - viewDidLoad

    NSLog(@"detailItem 1%@", detailItem);
self.greekTextField.text = [self.detailItem valueForKey:@"greekText"];
    self.englishTextField.text = [self.detailItem valueForKey:@"englishText"];
       

Solution

  • What if you use the Core data's @dynamic properties?

    self.greekTextField.text = self.detailItem.greekText;    
    self.englishTextField.text = self.detailItem.englishText;