Why isn't my managed object context being created? - iphone

Ok. I have a big problem. I recently downloaded FRLayeredNavigationController using Cocoapods. Before using it and simply using the UINavigationController, everything was working fine. Now its just a big mess. This is what I have after running the application:
This is my code:
AppDelegate.h
#import <UIKit/UIKit.h>
#import "FRLayeredNavigationController/FRLayeredNavigation.h"
#interface TasksAppDelegate : UIResponder <UIApplicationDelegate>
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (strong, nonatomic) FRLayeredNavigationController *layeredNavigationController;
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
ToDoTableViewController *tableViewController = [[ToDoTableViewController alloc]init];
self.layeredNavigationController = [[FRLayeredNavigationController alloc]initWithRootViewController:tableViewController];
tableViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.layeredNavigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
In my console I am getting the following:
DEBUG: self: 'ToDoTableViewController: 0x9537600', self.parentViewController: '(null)'
So basically what I can tell is that either for some reason FRLayeredNavigationController is not being created, or that the managed object context is not being created. I have no idea why. Literally if I change the FRLayeredNavigationController to UINavigationController, everything works fine >.>
If it makes any difference, TableViewController is not a UITableViewController, but rather a UIViewController with a tableView inside of it.

The ToDoTableViewController is not getting generated here. ManagedContext does not seem to be causing this. In your ToDoTableViewController do you have a property named 'parentViewController' which you are trying to access ?

Because of your breakpoint: Maybe check for random breakpoints in Xcode: Press ⌘+6 in Xcode to see all breakpoints. The log message however comes from a known limitation in FRLayeredNavigationController: You cannot use self.layeredNavigationItem (or someViewController.layeredNavigationItem) until the view controller (self or someViewController) is actually pushed onto the screen.
FRLayeredNavigationController's documentation on layeredNavigationItem mentions that:
Warning: This property is nil until the view controller is shown on the screen. To configure the FRLayeredNavigationItem before appearing on the screen use the following methods:
[FRLayeredNavigationController initWithRootViewController:configuration:]
[FRLayeredNavigationController pushViewController:inFrontOf:maximumWidth:animated:configuration:]
The reason for that (I'm the developer of FRLayeredNavigationController) is that layeredNavigationItem is implemented by walking the view controller hierarchy and before the view controller is pushed, it's not in the hierarchy at all. Therefore, parentViewController is nil.

Related

Property not found in object type

I am working on a simple core data app that uses a tableview and a detail view. I am getting the error message stating that the property managedObjectContext is not found in the object type ChildrenTVC. The problem is that it really is there. I have cleaned the project and deleted the derived data. There must be something else going on.
Here is the code for the object header:
#interface ChildrenTVC : CoreDataTableViewController <AddChildTVCDelegate>
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
#end
and the code for the implementation file:
#import "ChildrenTVC.h"
#implementation ChildrenTVC
#synthesize managedObjectContext = _managedObjectContext;
#synthesize fetchedResultsController = _fetchedResultsController;
Here is the app delegate file where the error registers:
#import "AppDelegate.h"
#import "ChildrenTVC.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize managedObjectContext = __managedObjectContext;
#synthesize managedObjectModel = __managedObjectModel;
#synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: ( NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
ChildrenTVC *controller = (ChildrenTVC *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
The error is at the controller.managedObjectContext. A lot of this is boilerplate code so there is not much to it. I just can't figure out why it is not seeing the property for the managed object context. The property is in the code.
UPdate:
I ended up recreating the file entirely. I am not sure what references are still in place when a file is changed, but something was pointing to the wrong file. I had to empty the trash to get the new file work properly. It seems to work now, though. All the research I did ended up revealing that there are some things that are unexplained in Xcode.
I had solved this issue by entirely recreating the header file, but I never really understood why it happened. What I did not understand then were the effects of the changes that I had made to the app. The real problem was an issue in the sequence that the header files were imported. I had changed the #import in two implementation files and that caused the compiler to not read one of the header files. I could see that the code was there, but the compiler could not read the code because it was not importing it. That gave way to the error I was receiving. My solution simply reversed the change that I had made. It would more easily have been solved by simply removing the #import of the view controller header file on the app delegate. I recently tested this and it was the correct solution.
You are type casting the navigationController.topViewController but i assume it isn't one in reality. Try this
ChildrenTVC *controller = [[ChildrenTVC alloc] init];
NSArray *vcArray = NSArray *vcArray = [NSArray arrayWithObject:controller]:
[self.window.rootViewController setViewControllers:vcArray animated:NO];
What happens if you make following changes to ChildrenTVC.h
#interface ChildrenTVC : CoreDataTableViewController <AddChildTVCDelegate>
{
NSManagedObjectContext *managedObjectContext;
NSFetchedResultsController *fetchedResultsController;
}
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
#end

how to add a login screen before existing ViewController in Xcode3

I need to add a screen to capture username and password before loading the first view of an app on an iPhone. The whole app is coded and working except for this (late) addition. This is my first app in Xcode so I am not very familiar with the system at all.
I have a LoginViewController set up, but don't know how to add it to the front of the app so that it loads first and then loads my RootViewController afterwards (I need the login details before loading the next view).
The header of my appdelegate is presently
#import <UIKit/UIKit.h>
#class RootViewController;
#interface Online_HW_DiaryAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#property (nonatomic, retain) IBOutlet RootViewController *viewController;
#end
but I'm not sure what I need to modify - or indeed what else will need to be modified? Any advice gratefully appreciated.
I think the fastest path is this: In viewDidAppear of RootViewController, detect the login needed condition and present a new LoginVC modally.
// RootViewController.m
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (/* user must login */) {
LoginVC *newVC = [[LoginVC alloc] initWithNibName:.....];
[self presentModalViewController:newVC animated:YES];
} else {
// your old viewwillappear logic
}
}
The LoginVC, upon determining that the user has logged in successfully, can dismiss itself.
// LoginVC.m
- (void)loginFinished {
// after some asynch call that validated the user credentials
[self dismissModalViewControllerAnimated:YES];
}

Adding UIViewController subclass with IBOutlet

I have seen this example on Apple's website before, but for some reason, I cannot find it and am brainfarting. I created a TestViewController.h and .m file that subclass from UIViewController and have a .xib. In the TestAppDelegate.h, I have:
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
Then in my MainWindow.xib, I drag a ViewController, change the class to TestViewController, control drag the outlet from TestAppDelegate to TestViewController. It builds fine, but when I run it I get:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestViewController 0x4d06570> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
I cannot remember what I'm missing in these steps. Any help would be appreciated. Thanks.
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
IF IT IS THE CODE YOU ARE REALLY USING THEN ADD FOLLOWING LINE TO YOUR INTERFACE:
UIWindow *window;
AND CHECK IF IT HELPS.
For your window you need to setup you rootViewController. By the way your naming "rootController" is kind of misleading, b/c UIWindow has a property rootViewController.
So to get this to work instead line [self.window addSubview:rootController.view]; you should do this self.window.rootViewController = self.rootController;
If you want to compare your code with a working code just create new project from template. Choose View-Based Application it has the schema you are looking for.
Open the TestViewController.xib and check whether any false outlets are connected there. Select the FilesOwner and go to connection inspector. The false outlets will be shown faded.. In this case, it would be label
Check your outlets in Interface Builder, you have something named "label" that does not exist. Remove the reference to this and you should be good to go.
again checkout....
use the connection inspector and write nib name and class name....in main View Controller.Xib

Passing info from Facebook to UITabBarController

When my app first starts, it shows a main page to log in to Facebook. Then, it goes to the UITabBarController. The code that I have in my app delegate is the following:
//this is the .h
#interface NMeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *controller;
UITabBarController *tabBar;
}
#property (nonatomic, retain) IBOutlet UITabBarController *tabBar;
#property (nonatomic, retain) MainViewController *controller;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
//this is the .m of the app delegate
#import "NMeAppDelegate.h"
#implementation NMeAppDelegate
#synthesize window;
#synthesize tabBar;
#synthesize controller;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
controller = [[MainViewController alloc] init];
[window addSubview:tabBar.view];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
Inside of MainViewController, I actually have a UserInfo object, which has all of the information that I need for the UITabBarController. The problem is that after getting this info in the UITabViewController, how do I pass this UserInfo to the UITabBarController` or possible the ViewController that is inside the UITabBarController so they were able to access this UserInfo? How to do this?
I hope my question makes sense.
you need to have an instance of your UserInfo object available to the tab bar controller. probably pass it into a instance variable of type UserInfo in your UItabBarController/each view controller whenever you transition into the specified controller.
edit: you should really have this passed into the view Controller it needs to be in (since it doesn't appear you have a custom UITabBarController subclass), or you could use a shared UserInfo variable in your app delegate to keep up with the information.
But as the commenter said, the question is not very clear at all and i could be completely misunderstanding what you want to do.
Hope that helps.

Where is the UIWindow instantiated in an iPhone app?

When you create an application from the "View-Based" template in the iPhoneSDK the following code is generated. I basically understand what is happening here, but I do not see where window and viewController are instantiated. Any Help?
#class jojojViewController;
#interface jojojAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
jojojViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet jojojViewController *viewController;
#end
===============================================
#implementation Test6AppDelegate
#synthesize window,mainView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
#end
They come from the MainWindow.xib (or similar) file in your project.
This is the file that in your info.plist is set as the application window. When your application starts this xib is loaded and the viewcontroller and window are unarchived and loaded.
If you look in MainWindow.xib, the window and viewcontroller are assigned to your AppDelegate's window and viewController outlets, which instantiates them when the nib is loaded (right click on the AppDelegate to see it).