Blank/black Screen in ios simulator on startup - ios

I am trying to input user information into coredata so that I can than send it to my php and do a MySQL login. However, when I was testing JUST the coredata part, all I got was a black/blank screen with no xcode error or error reports (after the custom image loading screen, there should me my background and my buttons). Below is my code, obviously excluding storyboard and the xcdatamodeld (to actually store the core data input). Anything I am doing wrong?
Appdelegate.h
#import <UIKit/UIKit.h>
#class LoginViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
LoginViewController *viewController;
}
#property (strong, nonatomic) IBOutlet LoginViewController *viewController;
#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;
#end
Appdelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize managedObjectContext = __managedObjectContext;
#synthesize managedObjectModel = __managedObjectModel;
#synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
#synthesize viewController;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
return YES;
}
LoginViewController.h
#import <UIKit/UIKit.h>
#interface LoginViewController : UIViewController {
UITextField *username;
UITextField *password;
}
#property (strong, nonatomic) IBOutlet UITextField *username;
#property (strong, nonatomic) IBOutlet UITextField *password;
- (IBAction)saveData:(id)sender;
#end
LoginViewController.m
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "Contacts.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
#synthesize username, password;
- (IBAction)saveData:(id)sender {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:#"Contacts" inManagedObjectContext:context];
[newContact setValue:username.text forKey:#"username"];
[newContact setValue:password.text forKey:#"password"];
username.text = #"";
password.text = #"";
NSError *error;
[context save:&error];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#end
Contacts.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#interface Contacts : NSManagedObject
#property (nonatomic, retain) NSString * username;
#property (nonatomic, retain) NSString * password;
#end
Contacts.m
#import "Contacts.h"
#implementation Contacts
#dynamic username;
#dynamic password;
#end

Reason is , you are not adding any viewcontrollers in your window.
Just add your logincontroller on it,
like
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubView:viewController.view];
// OR self.window.rootController = viewController;
[self.window makeKeyAndVisible];
return YES;
}

Related

objective C making UITextField for vc1 become UILabel vc2

I am trying to get my UITextField email in my first view controller to become the UILabel in my next view controller. It says there is an error stating there is no visible #interface for NSString declares the selector initvalue. I thought the interface was being loaded from the vc1.h file when you imported it on the vc2? any help would be nice. Heres what I have so far:
vc1.h
#import <UIKit/UIKit.h>
#interface loginUserViewController : UIViewController
#property (nonatomic, retain, strong) IBOutlet UITextField *email;
#property (nonatomic, retain) IBOutlet UITextField *password;
#property (nonatomic, retain) IBOutlet UIButton *login;
#property (nonatomic,retain) IBOutlet UIButton *registerBtn;
-(IBAction)loginUser:(id)sender;
#end
vc2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *username;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *Nav;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *logout;
-(IBAction)logout:(id)sender;
-(IBAction)bandHome:(id)sender;
#end
vc2.m
import "Home.h"
#import "loginUserViewController.h"
#interface Home ()
#end
#implementation Home
#synthesize username, band1, band2, band3;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
loginUserViewController *object = [[loginUserViewController alloc]init];
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
username.text = string;
}
vc1.m
#import "loginUserViewController.h"
#import "Home.h"
#import "createBandViewController.h"
#interface loginUserViewController ()
#end
#implementation loginUserViewController
#synthesize email, password;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidload
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setEmail:nil];
[self setPassword:nil];
[super viewDidUnload];
}
-(IBAction)loginUser:(id)sender {
if ([email.text isEqualToString:#""] || [password.text isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"alert" message:#"Please Fill all the field" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
Simply replace this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
with this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text intValue]];
and if you want simply the email just as a string then replace it with this string
NSString *string = [[NSString alloc] initWithFormat:#"%#",object.email.text];
your error will be resolved.Hope it helps :)
First of All in VC2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *username; // Keep property strong to get the value
in VC2.m
#synthesize username;
Now in VC1.h
#import <UIKit/UIKit.h>
#import "homeviewcontroller.h"
#interface loginUserViewController : UIViewController
#property (nonatomic, strong) IBOutlet UITextField *email;
#property (nonatomic, strong) IBOutlet UITextField *password;
#property (nonatomic) nsstring *username;
-(void)viewDidLoad
{
[super viewDidLoad];
username= self.email.text;
homeviewcontroller *object = [[homeviewcontroller alloc]init];
object.username.text=username;
}

Cannot set the value of a NSString from another class

I've searched all over google, and stack overflow for a solution, but I wasn't able to find an answer that solved my problem. Sorry for the long post, as I'm trying to give as much information as I can. I'm new to iOS and Objective- c, but not programming in general due to being asked to switch over from Android by my company, so any help is appreciated.
I'm trying to assign a value to an NSString in one class from a TextField in another, but I get the error:
**-[ViewController name:]: unrecognized selector sent to instance 0x78712fe0**
when I run the app in the simulator.
Relevant code:
//UserInfo.h
#import <Foundation/Foundation.h>
#interface UserInfo : NSObject <NSCoding>
#property (nonatomic, strong) NSString *name;
#property (nonatomic, strong) NSString *age;
#property (nonatomic, strong) NSString *address;
#end
//UserInfo.m
#import "UserInfo.h"
static NSString *nameKey = #"userName";
static NSString *ageKey = #"userAge";
static NSString *addressKey = #"userAddress";
static NSString *userInfoKey = #"userInfoKey";
#implementation UserInfo
#synthesize name;
#synthesize age;
#synthesize address;
- (id) initWithCoder:(NSCoder *)coder
{
self = [super init];
self.name = [coder decodeObjectForKey:nameKey];
self.age = [coder decodeObjectForKey:ageKey];
self.address = [coder decodeObjectForKey:addressKey];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.name forKey:nameKey];
[coder encodeObject:self.age forKey:ageKey];
[coder encodeObject:self.address forKey:addressKey];
}
#end
//ViewController.h
#import <UIKit/UIKit.h>
#import "UserInfo.h"
#interface ViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, NSCoding>
#property (nonatomic, strong) UserInfo *userInfoObject;
#property (nonatomic, weak) IBOutlet UILabel *titleLabel;
#property (nonatomic, weak) IBOutlet UILabel *nameLabel;
#property (nonatomic, weak) IBOutlet UILabel *ageLabel;
#property (nonatomic, weak) IBOutlet UILabel *addressLabel;
#property (nonatomic, weak) IBOutlet UITextField *nameText;
#property (nonatomic, weak) IBOutlet UITextField *ageText;
#property (nonatomic, weak) IBOutlet UITextField *addressText;
#property (nonatomic, weak) IBOutlet UIButton *saveBtn;
- (IBAction)saveBtnTouched:(id)sender;
- (void) saveUserInfo;
- (void) loadUserInfo;
- (void) setUserInterfaceValues;
- (IBAction)nameText:(id)sender;
- (IBAction)ageText:(id)sender;
- (IBAction)addressText:(id)sender;
#end
//ViewController.m
#import "ViewController.h"
#import "UserInfo.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize titleLabel;
#synthesize nameLabel;
#synthesize ageLabel;
#synthesize addressLabel;
#synthesize nameText;
#synthesize ageText;
#synthesize addressText;
#synthesize saveBtn;
static NSString *userInfoKey = #"userInfoKey";
- (void)viewDidLoad {
[super viewDidLoad];
[self loadUserInfo];
if(!self.userInfoObject)
{
self.userInfoObject = [[UserInfo alloc] init];
}
[self setUserInterfaceValues];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
self.saveBtn.enabled = YES;
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
return YES;
}
- (BOOL) textFieldShouldEndEditing:(UITextField *)textField
{
[self.nameText resignFirstResponder];
[self.ageText resignFirstResponder];
[self.addressText resignFirstResponder];
return YES;
}
- (IBAction)saveBtnTouched:(id)sender
{
NSLog(#"%# was entered into the name field", self.nameText.text);
NSLog(#"%# was entered into the age field", self.ageText.text);
NSLog(#"%# was entered into the address field", self.addressText.text);
[self textFieldShouldEndEditing:self.nameText];
[self textFieldShouldEndEditing:self.ageText];
[self textFieldShouldEndEditing:self.addressText];
self.userInfoObject.name = self.nameText.text;
self.userInfoObject.age = self.ageText.text;
self.userInfoObject.address = self.addressText.text;
[self saveUserInfo];
self.saveBtn.enabled = NO;
}
- (void)saveUserInfo
{
NSData *userInfoData = [NSKeyedArchiver archivedDataWithRootObject:self.userInfoObject];
[[NSUserDefaults standardUserDefaults] setObject:userInfoData forKey:userInfoKey];
}
- (void)loadUserInfo
{
NSData *userInfoData = [[NSUserDefaults standardUserDefaults] objectForKey:userInfoKey];
if(userInfoData)
{
self.userInfoObject = [NSKeyedUnarchiver unarchiveObjectWithData:userInfoData];
}
}
- (void) setUserInterfaceValues
{
self.nameText.text = self.userInfoObject.name;
self.ageText.text = self.userInfoObject.age;
self.addressText.text = self.userInfoObject.address;
}
- (IBAction)nameText:(id)sender {
}
- (IBAction)ageText:(id)sender {
}
- (IBAction)addressText:(id)sender {
}
#end
//AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#import "UserInfo.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#end
//AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "UserInfo.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
//all the other generated methods. Taken out due to space.
#end
Three breakpoints are set that are supposidly the source of the problem:
From the ViewController.m, in - (void)setUserInterfaceValues
self.nameText.text = self.userInfoObject.name;
(I assume that this applies to the other two lines below it also)
Also from the ViewController.m, in - (void)viewDidLoad
[self setUserInterfaceValues];
And finally from the AppDelegate.m, in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window.rootViewController = self.viewController;
From what I understand, and have learned from searching this issue, the app is trying to send data to something that doesn't exist, the NSString name being the culprit. Others have suggested to make sure that my .xib file is connected to the ViewController, and I have verified that it is.
As another bit of information, I'm not using a storyboard for this app, and instead am using the interface builder. I'm aware that there are advantages to storyboards, and I would like to be using them, but my company uses the interface builder and does a lot of things programmatically, so I'm learning to develop without.
[EDIT]: Issue solved thanks to Ian.

Creating image frame not displaying in simulator

I have an app that captures the users signature, myviewcontroller displays the signature capture. I'm attempting to create a rectangle in the center of the screen that is centered for this to happen using CGRect. When I run this I get no errors, but I get the picture below and I can't figure out what is causing this.
Within the CGRect code, I am trying to have the rectangle that is created be centered in the middle of the screen, and the target device is ipad. I've posted both the .h and .m files, the .m file is incomplete as the rest has to do with the code used to capture the signature then save it.
Any help would be appreciated.
//MyViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#interface MyViewController : UIViewController <UIAlertViewDelegate>
#property (nonatomic, strong) UIImageView *mySignatureImage;
#property (nonatomic, assign) CGPoint lastContactPoint1, lastContactPoint2, currentPoint;
#property (nonatomic, assign) CGRect imageFrame;
#property (nonatomic, assign) BOOL fingerMoved;
#property (nonatomic, assign) float navbarHeight;
#property (nonatomic, assign) UIImageView* imageView;
#property (nonatomic, retain) NSData*image;
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
//Save and cancel buttons
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;
#end
//MyViewController.m
#import "MyViewController.h"
#interface MyViewController ()
#end
#implementation MyViewController
#synthesize mySignatureImage;
#synthesize lastContactPoint1, lastContactPoint2, currentPoint;
#synthesize imageFrame;
#synthesize fingerMoved;
#synthesize navbarHeight;
#synthesize image;
#synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect imageFrame = CGRectMake(
CGRectGetMidX(self.view.frame) - CGRectGetMidX(imageView.frame),
CGRectGetMidY(self.view.frame) - CGRectGetMidY(imageView.frame),
CGRectGetWidth(imageView.frame),
CGRectGetHeight(imageView.frame));
// //allocate an image view and add to the main view
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
mySignatureImage.frame = imageFrame;
mySignatureImage.backgroundColor = [UIColor whiteColor];
[self.view addSubview:mySignatureImage];
}
Move the code (except for [super viewDidLoad]) in viewDidLoad to a later stage, such as viewWillAppear. During viewDidLoad the layout of the views is not yet complete so their bounds/frames are not yet set to their final values.
Try to replace this line:
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
with:
mySignatureImage = [[UIImageView alloc] init];

First ios application giving blank white screen

I am getting black screen when i initially run on my iphone.When i disconnect my iphone from my mac and open the applications a plain white screen opens.Please Help.
BNRQuizTableViewController.h
#import <UIKit/UIKit.h>
#import "BNRQuizTableViewController.h"
#interface BNRQuizTableViewController : UITableViewController
#end
BNRQuizTableViewController.m
#import "BNRQuizTableViewController.h"
#interface BNRQuizTableViewController ()
#property (nonatomic) int currentQuestionIndex;
#property (nonatomic, copy) NSArray *questions;
#property (nonatomic, copy) NSArray *answers;
#property (nonatomic,weak) IBOutlet UILabel *questionLabel;
#property (nonatomic,weak) IBOutlet UILabel *answerLabel;
#end
#implementation BNRQuizTableViewController
-(IBAction)showQuestion:(id)sender
{
{
// Step to the next question
self.currentQuestionIndex++;
// Am I past the last question?
if (self.currentQuestionIndex == [self.questions count])
{
// Go back to the first question
self.currentQuestionIndex = 0;
}
// Get the string at that index in the questions array
NSString *question = self.questions[self.currentQuestionIndex];
// Display the string in the question label
self.questionLabel.text = question;
self.answerLabel.text=#"???";
}
}
-(IBAction)showAnswer:(id)sender
{
{
// What is the answer to the current question?
NSString *answer = self.answers[self.currentQuestionIndex];
// Display it in the answer label
self.answerLabel.text = answer;
}
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
// Call the init method implemented by the superclass
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Create two arrays filled with questions and answers
// and make the pointers point to them
self.questions = #[#"What is the name of the first prophet?",
#"What is the name of the last prophet",
#"Who was the first caliph ?"];
self.answers = #[#"Prophet Adam(A.S)",
#"Propher Mohammed(S.A.W)",
#"Hazrat Abu bakar"];
}
// Return the address of the new object
return self;
}
#end;
BNRAppDelegate.h
#import <UIKit/UIKit.h>
#interface BNRAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
BNRAppdelegate.m
#import "BNRAppDelegate.h"
#import "BNRQuizTableViewController.h"
#implementation BNRAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
BNRQuizTableViewController *quizvc = [[BNRQuizTableViewController alloc]init];
self.window.rootViewController=quizvc;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#end
You need to specify the nib name for your view controller with initWithNibName:bundle: otherwise the view controller will have no valid view assigned:
BNRQuizTableViewController *quizvc = [[BNRQuizTableViewController alloc] initWithNibName#"YOUR_NIB_NAME_HERE" bundle:[NSBundle mainBundle]];

cant connect my managedObjectContext from my view to my Delegate

i'm using core data on my app and i know i need to connect my managedObjectContext throw the Delegate but i don't know how...
i have a delegate-
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;
#property (strong, nonatomic) UINavigationController *nav;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
AppDelegate.m:
#import "AppDelegate.h"
#import "mainViewController.h"
#import "addViewController.h"
#implementation AppDelegate
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
#synthesize nav;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
//----------------------------------nav-------------------------------------------------
mainViewController*mainView=[[mainViewController alloc]init];
nav=[[UINavigationController alloc]initWithRootViewController:mainView];
mainView.manageObjectContext=self.managedObjectContext;
[self.window addSubview:nav.view];
//----------------------------------nav-end---------------------------------------------
[self.window makeKeyAndVisible];
return YES;
}
the MainVeiw is not the page that i want to save an Entity in (so i cant Match the objects from the delegate itself), that is another page and i think my problem is that i dont know how to import a delegate id object so i can compare the managedObjectContext to the one on my delegate.
addViewController.h:
#import <UIKit/UIKit.h>
#interface addViewController : UIViewController <UIPickerViewAccessibilityDelegate,UIPickerViewDataSource,UITextFieldDelegate>
{
NSDictionary *allSubjects;
NSArray* arrSubject;
NSArray* arrSubSubjects;
NSManagedObjectContext*manageObjectContext;
}
#property(nonatomic,strong)NSManagedObjectContext*manageObjectContext;
//#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
//#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
#property (strong, nonatomic) NSDictionary *allSubjects;
#property (strong, nonatomic) NSArray* arrSubject;
#property (strong, nonatomic) NSArray* arrSubSubjects;
#property (weak, nonatomic) IBOutlet UIScrollView *scrolladdview;
#property (weak, nonatomic) IBOutlet UIPickerView *pickerSubjects;
#property (weak, nonatomic) IBOutlet UITextField *txtDesc;
#property (weak, nonatomic) IBOutlet UITextField *txtUserName;
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
-(IBAction)createPassword:(id)sender;
#end
addViewController.m
#import "addViewController.h"
#interface addViewController ()
#end
#implementation addViewController
#synthesize allSubjects,arrSubject,arrSubSubjects,pickerSubjects;
#synthesize txtDesc,txtPassword,txtUserName,scrolladdview,manageObjectContext;
-(IBAction)createPassword:(id)sender
{
NSInteger row;
NSString*subTypeSelectd=[[NSString alloc]init];
row = [pickerSubjects selectedRowInComponent:0];
subTypeSelectd = [arrSubSubjects objectAtIndex:row];
NSInteger row2;
NSString*TypeSelectd=[[NSString alloc]init];
row2 = [pickerSubjects selectedRowInComponent:1];
TypeSelectd = [arrSubSubjects objectAtIndex:row2];
//here is the error: no visible #interface for 'addViewController' declares the selector 'NSManagedObject'
NSManagedObject*password=[NSEntityDescription insertNewObjectForEntityForName:#"Password" inManagedObjectContext:[self managedObjectContext]];
[password setValue:self.txtDesc.text forKey:#"desc"];
[password setValue:self.txtUserName.text forKey:#"userName"];
[password setValue:self.txtPassword.text forKey:#"password"];
[password setValue:subTypeSelectd forKey:#"subType"];
[password setValue:TypeSelectd forKey:#"type"];
NSError*error;
if(![[self manageObjectContext]save:&error])
NSLog(#"input %#",error);
else NSLog(#"saved");
[self.navigationController popViewControllerAnimated:YES];
}
i will love some help!!!
You could get it form the AppDelegate itself:
#import "AppDelegate.h"
//...
-(IBAction)createPassword:(id)sender
{
//...
NSManagedObjectContext* context = ((AppDelegate*)[[UIApplication sharedApplication] delegate]). managedObjectContext;
//...
}
Here in I see, you have created one context in the AppDelegate, and one in the Addviewcontroller.
Where as you have only one store and one thread, so you should remove the property of the managed object context from the AddviewController.
Also should assign the managedobjectcontext from the delegate in the addViewController by the following code:
{
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
NSManagedObjectContext *addViewcontrollerLocalContext = delegate.managedObjectContext;
}
By doing this all the objects would be saved in the MainObjectContext created by you in the AppDelegate file.

Resources