Use of undeclared identifier in AppDelegate? - nsmanagedobjectcontext

In my AppDelegate implementation file i get an error for an undeclared identifier but it appears to be declared, what am i overlooking?
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize managedObjectContext=__managedObjectContext;
#synthesize managedObjectModel=__managedObjectModel;
#synthesize persistentStoreCoordinator=__persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
- (NSManagedObjectContext *)managedObjectContext
the error occurs at this line "Use of undeclared identifier "managedObjectContext"
In my AppDelegate header file:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
#property (nonatomic, strong) NSManagedObjectModel *managedObjectModel;
#property (nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (NSURL *)applicationDocumentsDirectory;
- (void)saveContext;
#end

Related

How do I fix setManagedObjectContext error?

Whenever I run my app it always crashes and gives me this error:
2014-08-10 12:50:58.802 EIC Scanner[2184:133860] -[UITabBarController
setManagedObjectContext:]: unrecognized selector sent to instance
0x7ae7b9f0 (lldb)
I have an exception breakpoint so it leads me to this line of code:
rootView.managedObjectContext = self.managedObjectContext;
AppDelegate.h:
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
Part of AppDelegate.m:
#import "AppDelegate.h"
#import "NotesList.h"
#import <CoreData/CoreData.h>
#implementation AppDelegate
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// IMPORTANT: Pass the managedObjectContext to the root view controller
NotesList *rootView = (NotesList *)_window.rootViewController;
rootView.managedObjectContext = self.managedObjectContext;
return YES;
}
As requested NotesList.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface NotesList : UIViewController <
UITableViewDelegate,
UISearchBarDelegate, UISearchDisplayDelegate
>
// CoreData properties *******
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) NSMutableArray *notesArray;
//UI VIEWS ***********
#property (retain, nonatomic) IBOutlet UIView *topView;
//TableView ********
#property (retain, nonatomic) IBOutlet UITableView *tableView;
#end
If you know how to fix this, please comment on how. Thanks for the help!

Passing map-data between ViewController

I nearly followed this post. The viewcontroller will push via storyboard. Here the relevant code:
ViewController.m:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
MapPoint.h:
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_title;
NSString *_subtitle;
CLLocationCoordinate2D _coordinate;
UIImage *_storeImage;
}
#property (copy) NSString *title;
#property (copy) NSString *subtitle;
#property (nonatomic, readonly) UIImage *storeImage;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle coordinate:(CLLocationCoordinate2D)coordinate storeImage:(UIImage*)storeImage;
and DetailViewController:
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
I think my mistake is in the calloutAccessoryControlTapped method but I dont know what is the real reason for this issue.
If you use a storyboard, can use prepareForSegue method and set within a class similarly as you have made.
I post a portion of code
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"Brs"]){
NSLog(#"segue %# ",[segue identifier]);
[segue.destinationViewController setPath:[ris_xml objectAtIndex:index_post-1] ];
}
}
In this example I set attribute "Path" of next UIViewController only if his identifier is "Brs".
For use this method is need set UIviewController identifier into storyboard right panel.
Using this isn't need to instantiate new UIViewController if you have it in storyboard.
I solved it by thinking about loading sequence.
All what to do is create temporary #properties
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
#property (nonatomic) NSString *titleTMP; //added
#property (nonatomic) NSString *subtitleTMP; //added
and do
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
The DetailViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
titleLabel.text = titleTMP;
textView.text = subtitleTMP;
}

Adding a view as subview to my app's window but it is not displayed

I'm adding a view controller's view to my window in application:didFinishLaunchingWithOptions: but the view does not become visible. I'm not sure what's wrong.
Here's my app delegate code:
#class ToolBar;
#class MainViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *Window;
//UIToolbar *toolbar;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) MainViewController *mainViewController;
#property (strong, nonatomic) ToolBar *toolbar;
#end
#import "AppDelegate.h"
#import "MainViewController.h"
#import "ToolBar.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize mainViewController = _mainViewController;
#synthesize toolbar =toolbar;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
self.mainViewController = [[[MainViewController alloc]init]autorelease];
[self.window addSubview:self.mainViewController.view];
//[self.window makeKeyAndVisible];
self.toolbar = [[[ToolBar alloc]init]autorelease];
[self.window addSubview:toolbar.view];
[self.window makeKeyAndVisible];
return YES;
}
Well, to start with you're not setting the frame for your toolbar.
But why are you adding a toolbar to your app's main window? I would expect it to be a subview of your mainViewController's view.

using appDelegate to share data - getting "request for member in __ not in structure or union"

I've got a simple example where i have a delegate that has a string, along with a property to expose it.
myAppDelegate.h
#import <UIKit/UIKit.h>
#interface myAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
NSString* myText;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) NSString *myText;
#end
myAppDelegate.m
#import "myAppDelegate.h"
#implementation myAppDelegate
#synthesize window;
#synthesize rootController;
#synthesize myText;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:rootController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[rootController release];
[window release];
[super dealloc];
}
#end
So in my main view controller, I try something like this:
myAppDelegate* ad = (myAppDelegate*)[UIApplication sharedApplication].delegate;
ad.myText = #"blah";
and I get: Request for member 'myText' in something not a structure or union
does anyone know why this is happening?
Have you tried using setter instead of dot notation?
[ad setMyText:#"blah"];

error: expected specifier-qualifier-list before 'GKPeerPickerController

I keep getting this message (in the title). Just take a quick look at my code if you want to see what I'm doing. I've just started implementing the Peer Picker, so I'm not completely done yet. I just need some advice/help in the first part. The error shows up in the .m file between the two #import statements, which means it has to be some wrong way that I've used the GKPeerPickerController in the header file.
Bluetooth_Ad_Hoc_NetworkAppDelegate.h
#import <UIKit/UIKit.h>
#class Bluetooth_Ad_Hoc_NetworkViewController;
#interface Bluetooth_Ad_Hoc_NetworkAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
Bluetooth_Ad_Hoc_NetworkViewController *viewController;
GKPeerPickerController *picker;
GKSession *session;
IBOutlet UILabel *status;
NSData *data;
}
#property(nonatomic, retain)IBOutlet UILabel *status;
#property(nonatomic, retain)GKPeerPickerController *picker;
#property(nonatomic, retain)GKSession *session;
#property(nonatomic, retain)IBOutlet UIWindow *window;
#property(nonatomic, retain)IBOutlet Bluetooth_Ad_Hoc_NetworkViewController *viewController;
#end
Bluetooth_Ad_Hoc_NetworkAppDelegate.m
#import "Bluetooth_Ad_Hoc_NetworkAppDelegate.h"
#import "Bluetooth_Ad_Hoc_NetworkViewController.h"
#implementation Bluetooth_Ad_Hoc_NetworkAppDelegate
#synthesize status;
#synthesize picker;
#synthesize session;
#synthesize window;
#synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
// allocate and initialize data
data = [[NSData alloc] initWithBytes:&status length:sizeof(status)];
// Allocate and setup peer picker controller
picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[picker show];
}
- (void)dealloc {
[status release];
[viewController release];
[window release];
[super dealloc];
}
#end
Have you included this statement in the header file?
#import <GameKit/GameKit.h>
Also you need to include the GameKit framework.