Is there something important I need in RoomItem to ensure that this method isn’t skipped? It’s the very first one in my detail view controller, and it is continually skipped when I’m in debugging mode. I’m sure I’m missing something ridiculously simple, but I’ve been staring at it for hours and just can’t figure out what it is.
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
- (void)setDetailItem:(RoomItem *)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
[_roomTxt setText:[_detailItem room]];
[_buildingTxt setText:[_detailItem building]];
[_dateTxt setText:[self dateCreatedString]];
[_buildingImageView setImage:[_detailItem buildingImage]];
_oi = [_detailItem objectIndex];
}
}
MasterViewController (root table view) methods that alloc and init new and existing detailViewControllers
- (void)insertNewObject:(id)sender
{
//add button invokes this
DetailViewController *ivc = [[DetailViewController alloc] init];
[self.navigationController pushViewController:ivc animated:YES];
NSLog(@"detailViewController allocated and initialized: %@", ivc);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
NSLog(@"detailViewController initialized: %@", self.detailViewController);
}
//navigates to detailViewController and passes it the item's data
self.detailViewController.detailItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
Here is the tableView:didSelectRowAtIndexPath method that should be passing everything needed by the detail view controller, from the RoomList:sharedStore:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
//navigates to detailViewController and passes it the item's data
self.detailViewController.detailItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
…and the RoomItem.m file:
- (void)awakeFromFetch
{
[super awakeFromFetch];
UIImage *pic = [UIImage imageWithData:[self buildingThumbnailData]];
[self setPrimitiveValue:pic forKey:@"buildingThumbnail"];
}
- (id)initWithRoom:(NSString *)room Building:(NSString *)building
{
self = [super init];
if (self) {
[self setRoom:room];
[self setBuilding:building];
}
return self;
}
DetailViewController.h
#import <UIKit/UIKit.h>
@class RoomItem;
//pic edit: added delegates
@interface DetailViewController : UIViewController <UINavigationControllerDelegate,
UIImagePickerControllerDelegate, UITextFieldDelegate, UIPopoverControllerDelegate,
UIPageViewControllerDelegate>
{
__weak IBOutlet UITextField *roomField;
__weak IBOutlet UITextField *buildingField;
__weak IBOutlet UILabel *dateLabel;
UIPopoverController *imagePickerPopover;
}
@property (nonatomic, strong) RoomItem *detailItem;
@property (weak, nonatomic) IBOutlet UIButton *updateBtn;
@property (weak, nonatomic) IBOutlet UIButton *detailsBtn;
@property (weak, nonatomic) IBOutlet UITextField *roomTxt;
@property (weak, nonatomic) IBOutlet UITextField *buildingTxt;
@property (weak, nonatomic) IBOutlet UILabel *dateTxt;
@property (weak, nonatomic) IBOutlet UIImageView *buildingImageView;
@property (weak, nonatomic) UIImage *buildingImage;
@property (weak, nonatomic) NSNumber *oi;
- (IBAction)backgroundTapped:(id)sender;
- (IBAction)takePicture:(id)sender;
- (IBAction)updateRoomItem:(id)sender;
- (IBAction)goToReportDetails:(id)sender;
@end
Edit:here is a pseudo-UML diagram that illustrates what I’m seeing when I step through with the debugger (it reads from left to right, top to bottom):

Alrighty, first things first. The reason -(void)setDetailItem:(RoomItem *)newDetailItem was being skipped is due to me not passing it the newly created RoomItem in the DVC. I was doing this initially, but mistakenly got rid of it while trying to correct the issue somewhere else.
In DetailViewController.m:
Getting this to work though took some restructuring in the RoomList.m file. I had initially attempted to marry the create and update functions into one method. That doesn’t fly if I’m creating in the MVC, and updating in the DVC.
So I split the two up:
Lastly, the setDetailItem and configureView methods:
This should serve as a lesson about taking the time to read the core data documentation, or any other for that matter…especially noobs like myself.
Thanks again to emrys57 for the help.