Error: missing property on object 'AppDelegate *' - ios

Teaching myself iOS Programming, and starting by following this book.
I ran into error "Property 'MainViewController' not found on object of type 'AppDelegate *'.
I've double and triple checked that I followed the code correctly, even restarted from scratch. I've scoured StackOverflow and tried a few solutions but none worked and few properly match my issue. Any help?
AppDelegate.m (where the error lies)
#import "AppDelegate.h"
#import "WeatherForecast.h"
#import "MainViewController.h"
#implementation AppDelegate
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
WeatherForecast *forecast = [[WeatherForecast alloc] init];
self.MainViewController.forecast = forecast;
// Override point for customization after application launch.
MainViewController *controller = (MainViewController *)self.window.rootViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
MainViewController.h
#import "FlipsideViewController.h"
#import "WeatherForecast.h"
#import <CoreData/CoreData.h>
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
- (IBAction)showInfo;
- (IBAction)refreshView:(id) sender;
- (void)updateView;
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) WeatherForecast *forecast;
#end

The problem should be in your second line of application:didFinishLaunchingWithOptions. self.MainViewController is expecting a property in your AppDelegate. Just remove this line and add controller.forecast = forecast; before return YES. At this point you got a reference to your MainViewController and can set the property safely (assuming that MainViewController is set up as the current rootViewController through your Storyboard or XIB).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
WeatherForecast *forecast = [[WeatherForecast alloc] init];
// Override point for customization after application launch.
MainViewController *controller = (MainViewController *)self.window.rootViewController;
controller.managedObjectContext = self.managedObjectContext;
controller.forecast = forecast;
return YES;
}

Related

Unrecognized selector when calling delegate Method

I'm trying to implement a SplitViewController with a NavigationController in both master and detail. I have been following this tutorial, however I'm still running into a rather strange problem.
When I try to call the delegate method I get -[UINavigationController selectedStudent:]: unrecognized selector sent to instance...
Any help would be greatly appriciated.
Here's the code:
StudentSelectionDelegate.h
#import <Foundation/Foundation.h>
#class Student;
#protocol StudentSelectionDelegate <NSObject>
#required
-(void)selectedStudent:(Student *)newStudent;
#end
StudentDetail represents detail in the split view.
In StudentDetail.h I`ve got
#import "StudentSelectionDelegate.h"
#interface StudentDetail : UITableViewController <StudentSelectionDelegate>
...
StudentDetail.m
#synthesize SentStudent;
...
-(void)selectedStudent:(Student *)newStudent
{
[self setStudent:newStudent];
}
StudentList represents master of the splitview. In StudentList.h I`ve got :
#import "StudentSelectionDelegate.h"
...
#property (nonatomic,strong) id<StudentSelectionDelegate> delegate;
In StudentList.m in the didSelectRowAtIndexPath
[self.delegate selectedStudent:SelectedStudent];
And no "SelectedStudent" is not null
And finally AppDelegate.m
#import "AppDelegate.h"
#import "StudentDetail.h"
#import "StudentListNew.h"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *leftNavController = [splitViewController.viewControllers objectAtIndex:0];
StudentListNew *leftViewController = (StudentListNew *)[leftNavController topViewController];
StudentDetail *rightViewController = [splitViewController.viewControllers objectAtIndex:1];
leftViewController.delegate = rightViewController;
return YES;
}
P.S. I have been searching for a solution for hours.
[splitViewController.viewControllers objectAtIndex:1] is a UINavigationController, not a StudentDetail.
The error message is telling you that UINavigationController does not have a selectedStudent property.
Your delegate is not pointing to a StudentDetail but a navigation controller, which doesn't even implement < StudentSelectionDelegate>. However, since you specified the cast, Objective C can't warn you that the object you cast isn't actually the kind of class that you cast it to be.
You should consider type checking the objects, as Apple's code does, to make sure that objects are the class you expect them to be.
Here's the corrected code:
UINavigationController *rightNavController = [splitViewController.viewControllers objectAtIndex:1];
StudentDetail *rightViewController = (StudentDetail *)[rightNavController topViewController];
leftViewController.delegate = rightViewController;
As for making sure that your delegate implements the method,
if ([self.delegate respondsToSelector:#selector(selectedStudent:)]) {
[self.delegate selectedStudent:SelectedStudent];
}
would have spared you from the exception, although you'd have to have used the debugger to realize that self.delegate wasn't a StudentDetail.

SWRevealViewController Error. Build Fails, but no error

First of all, let me give you a heads-up. I'm moderately familiar with XCode (5) and Objective-C.
But, consider me a noob and please help me out.
I'm trying to build an app. I need a Slide out menu in all Views of the app.
I made a dummy project using SwRevealViewController Class. And I have made two slide out menus also. And it works.
I tried to use the same method in the App that I'm building.
But my build has failed with no Errors and a single warning, which I had in my previous dummy project....
I have already imported SwRevealViewController.h to AppDelegate.m and ViewController.m
I'm trying to use a TableViewController as slideout menu (which is empty, I haven't added any code to it yet). But the build is failing.
Edit:
" The error is as follows..
"#synthesize of 'weak' property is only allowed in ARC or GC Mode"
I'm using Core Data with my project. And I have to use webservice extensively in my App. So I have disabled ARC. "
I have also tried replacing table with other views, but the same result. Now I'm stuck.
I know its some thing with my code, but I couldn't find it.
I'm including code of AppDelegate.m and ViewController.m.
Please check it and tell me what is wrong. I'm at a loss here.
Edit:
" I cannot upload images due to Stack Overflow restrictions. So I have uploaded a screenshot of the error in tinypic. Here is the url.
http://tinypic.com/r/162vli/8 "
Thank you for all your help.
AppDelegate.h
// AppDelegate.h
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import <UIKit/UIKit.h>
#class SWRevealViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *UINV;
#property (strong, nonatomic) SWRevealViewController *splitMenu;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
AppDelegate.m
//
// AppDelegate.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "HomePageViewController.h"
#import "SlideOutMenuTableViewController.h"
#import "SearchViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "EmergencyViewController.h"
#implementation AppDelegate
#synthesize splitMenu,window,UINV;
#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.window = window;
HomePageViewController *HPVC = [[HomePageViewController alloc]init];
SlideOutMenuTableViewController *SOMTVC = SOMTVC = [[SlideOutMenuTableViewController alloc]init];
UINavigationController *frontNavigationController = [[UINavigationController alloc]initWithRootViewController:HPVC];
UINavigationController *rearNavigationController = [[UINavigationController alloc]initWithRootViewController:SOMTVC];
SWRevealViewController *revealController= [[SWRevealViewController alloc]initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate=self;
revealController.rightViewController = SOMTVC;
self.splitMenu = revealController;
self.window.rootViewController = self.splitMenu;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
HomePageViewController.m
//
// HomePageViewController.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "HomePageViewController.h"
#import "SWRevealViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#interface HomePageViewController ()
#end
#implementation HomePageViewController
#synthesize btn1SearchBlood,btn2DonateNow;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.055 green:0.055 blue:0.059 alpha:1]];
self.navigationController.navigationBar.translucent=NO;
SWRevealViewController *revealViewController = [self revealViewController];
[revealViewController panGestureRecognizer];
[revealViewController tapGestureRecognizer];
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"menu-icon"] style:UIBarButtonItemStyleBordered target:revealViewController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = menuButton;
}
The solution was simple, I just had to turn on ARC.
The basic requirement of SWRevealViewController Class is ARC enabled.
You cannot use this Class for slide out navigation with ARC disabled.
My bad guys. Thought I checked for errors with ARC enabled. My mistake.
So, if you encounter this error "#synthesize of 'weak' property is only allowed in ARC or GC Mode", just turn on ARC.

Property 'images' not found on object of type 'UIViewController *'

I'm trying to merge these two projects.
Bearded - An iPhone photo app
Thumbnail Picker View
At this point I'm just trying to keep these in separate view controllers and getting the functionality of the Thumbnail Picker working in it's own controller.
I'm getting the error, as stated in the title, "Property 'images' not found on object of type 'UIViewController *'"
The error is coming from the AppDelegate.m file:
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[UIViewController alloc] init];
NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:nil];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:paths.count];
for (NSString *path in paths) {
[images addObject:[UIImage imageWithContentsOfFile:path]];
}
self.viewController.images = images;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
#end
Here is the AppDelegate.h:
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UIViewController *viewController;
#end
I've tried declaring a property like so:
#property (strong, nonatomic) UIImageView *images;
I can't seem to fix this even though I painstakingly merged these two codebases.
Here is the Xcode project of where I'm at at this point:
Xcode project
the "images" property you've declared in your .h file:
#property (strong, nonatomic) UIImageView *images;
is not the NSMutableArray you are trying to assign to it via this line:
self.viewController.images = images;
If you can get the types to be the same (i.e. either a single UIImageView object or a NSMutableArray containing many UIImages), then you should have better luck with assigning things to that property.
I solved it. The problem was that I was merging a project using Storyboards and one that was using programmatically generated ViewController. Well, part of the problem.
Since, I merged the projects I had to give the view controller with the ThumbnailView another name. I named it ElfViewController.
This is the working code:
AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#class ElfViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ElfViewController *viewController; // Changed here to ElfViewController
#property (strong, nonatomic) ViewController *firstViewController;
#end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "ElfViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ElfViewController alloc] init]; //Changed here to ElfViewController
self.firstViewController = [[ViewController alloc] init];
NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:nil];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:paths.count];
for (NSString *path in paths) {
[images addObject:[UIImage imageWithContentsOfFile:path]];
}
self.viewController.images = images;
self.window.rootViewController = self.firstViewController;
[self.window makeKeyAndVisible];
}
#end
I'm still new to Objective-C and have only learned how to create ViewControllers in Storyboard and not programmatically.
Also I didn't know that you can declare a property to a specific View Controller rather than just a general UIViewContoller. That's another place I got tripped up.

ivar behave in 2 different way, with same usage

i tried 2 different apps to test few things.
the first app its simple
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
NSMutableString *text;
}
#property (nonatomic, retain)NSMutableString *text;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize text = text;
- (void)viewDidLoad
{
[super viewDidLoad];
text = #"FOO";
NSLog(#"%#", text);
self.text = #"FOO2";
NSLog(#"%#", self.text);
NSLog(#"1:%# - 2:%#", text, self.text);
}
this made things seems like synthesizing with same name, makes them the same variable. cause it print this:
2013-09-05 11:20:14.527 testIvar[12965:c07] FOO
2013-09-05 11:20:14.528 testIvar[12965:c07] FOO2
2013-09-05 11:20:14.529 testIvar[12965:c07] 1:FOO2 - 2:FOO2
even if i use %p to print the address memory of text and self.text i get the same address
*my other app test is this *
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSManagedObjectContext *managedObjectContext;
NSManagedObjectModel *managedObjectModel;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
}
#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;
#property ( strong, nonatomic ) UINavigationController *navigationController;
#end
AppDelegate.m
#import "AppDelegate.h"
#import "MasterViewController.h"
#implementation AppDelegate
#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.
MasterViewController *masterVC = [[MasterViewController alloc]initWithNibName:#"MasterViewController" bundle:nil];
masterVC.MOC = managedObjectContext;
self.navigationController = [[UINavigationController alloc]initWithRootViewController:masterVC];
[self.window setRootViewController:self.navigationController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
this app won't work if i do
masterVC.MOC = managedObjectContext;
but only work if i do
masterVC.MOC = self.managedObjectContext;
even if i print the mem address of managedObjectContext and self.managedObjectContext
i get 2 different addresses
how is that possible? same thing in 2 different app, behave in 2 different way?!?!?!?!?!?!?!?!?
masterVC.MOC = self.managedObjectContext; only works because the getter method has been overridden in that case.
See carefully and you will find that in your AppDelegate, there is a method
- (NSManagedObjectContext *)managedObjectContext
When you refer the object by self., the overridden getter method is called.

Tab Bar does not let Facebook Login to Appear IOS

I am trying to make a tab bar application, first i followed This Facebook grap api tutorial and my project was working fine like in picture when I touch to login, display popups
after that I have added only a tab bar and I am lost, No errors but program does not launch facebook login display. I have used breakpoints to understand why program doesnt launch facebook login display but couldnt understand because it just stuck no errors. it has to be something with tab bar.
Now it programs stucks at popin up facebook login display
my app delegate.h
#import <UIKit/UIKit.h>
#class FBFunMe;
#interface FBFunAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#end
app delegate.m
#import "FBFunAppDelegate.h"
#import "FBFunMe.h"
#import "FBFunLoginDialog.h"
#implementation FBFunAppDelegate
#synthesize window = _window;
#synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
I know rest of the code is working because i have an identical project without tab bar that works fine.
Any suggestion or example code to make it work?
_____-----------EDIT------------________
In app delegate when i try this code it display FBFunLoginDialog which what i need but i still need to this in my login button not in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
because i call some variables and appID and staff in order to login to the Facebook
FBFunLoginDialog *loginController=[[FBFunLoginDialog alloc] init];
[self.window addSubview:rootController.view];
[self.rootController presentModalViewController:loginController animated:YES];
[window makeKeyAndVisible];
return YES;
in FBFunMe.h
#interface FBFunMe :UIViewController <FBFunLoginDialogDelegate,UITextFieldDelegate> {
FBFunLoginDialog *_loginDialog;
UIView *_loginDialogView;
}
in FBFunMe.M
- (IBAction)loginButtonTapped:(id)sender {
NSString *appId = #"3888888883";
NSString *permissions = #"publish_stream";
if (_loginDialog == nil) {
self.loginDialog = [[[FBFunLoginDialog alloc] initWithAppId:appId
requestedPermissions:permissions delegate:self] autorelease];
self.loginDialogView = _loginDialog.view;
}
if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
_loginState = LoginStateLoggingIn;
[_loginDialog login];
} else if (_loginState == LoginStateLoggedIn) {
_loginState = LoginStateLoggedOut;
[_loginDialog logout];
}
[self refresh];
}

Resources