I fix all warnings and now I have such error in my AppDelegate Class
.h file is
#import <UIKit/UIKit.h>
#interface UYLAppDelegate : UIResponder <UIApplicationDelegate>{
}
#property (retain, nonatomic) IBOutlet UIWindow *window;
#property (retain, nonatomic) IBOutlet UISplitViewController *splitViewController;
#end
.m file is
#import "UYLAppDelegate.h"
#import "UYLMasterViewController.h"
#import "UYLDetailViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation UYLAppDelegate
#synthesize window = _window;
#synthesize splitViewController = _splitViewController;
- (void)dealloc
{
[_window release];
[_splitViewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIView *rootView = [[self.splitViewController.viewControllers objectAtIndex:0] view];
rootView.layer.borderWidth = 1.0f;
rootView.layer.cornerRadius =5.0f;
rootView.layer.shadowOpacity = 0.8f;
rootView.layer.shadowOffset = CGSizeMake(-5, 0);
self.window.rootViewController = self.splitViewController; //error here
[self.window makeKeyAndVisible];
return YES;
}
#end
in this row I take an error
self.window.rootViewController = self.splitViewController; //error here
SplitViewController consist of 2 controllers, .h file are:
#import <UIKit/UIKit.h>
#class UYLDetailViewController;
#interface UYLMasterViewController : UITableViewController
#property (retain, nonatomic) IBOutlet UYLDetailViewController *detailViewController;
#end
and the second
#import <UIKit/UIKit.h>
#import "UYLModalViewController.h"
#class UYLMasterViewController;
#interface UYLDetailViewController : UIViewController <UYLModalViewControllerDelegate>{
UIBarButtonItem *_MessageButton;
NSInteger modalViewShowType;
}
-(IBAction)buttonTapped:(id)sender;
#property (retain, nonatomic, getter=_MessageButton) IBOutlet UIBarButtonItem *someMessageButton;
#property (retain, nonatomic) NSNumber *detailItem;
#property (retain, nonatomic) IBOutlet UIToolbar *toolbar;
#property (retain, nonatomic) IBOutlet UILabel *detailTitle;
#property (retain, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#property (assign, nonatomic) BOOL masterIsVisible;
#end
edit:
there is all I see in console
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 8217.
Pending breakpoint 1 - ""UYLDetailViewController.m":117" resolved
Pending breakpoint 2 - ""UYLModalViewController.m":30" resolved
Pending breakpoint 3 - ""UYLModalViewController.m":41" resolved
Pending breakpoint 4 - ""UYLDetailViewController.m":63" resolved
Pending breakpoint 5 - ""UYLMasterViewController.m":46" resolved
Pending breakpoint 7 - ""UYLDetailViewController.m":36" resolved
No breakpoint number 7.
Current language: auto; currently objective-c
Please help me to understand it =(
I had some SIGABRT errors most of the time, it just means that it can't find that instance you are referring to. So look at that line again and think what might not be declared right.
I think it might help if you change it to.
self.window.rootViewController = splitViewController;
Related
I am just learning and trying to put forth some of the knowledge with objective c and cocoa. I have a little program that has a login screen which then displays a main menu. On the main menu view, there is a button that should load a view to be able to add some data to the app. When I click on the button, it doesn't fire the IBAction but throws an error
EXC_BAD_ACCESS [StartMenuViewController performSelector:withObject:]: message sent to deallocated instance 0x6080195e9f90
I know that it is because there is an object that is not instantiated when the message is being sent, but I cannot find out why. Sorry for the code and the novice level here is the main menu view controller StartMenuViewController.m file:
#import "StartMenuViewController.h"
#import "AppDelegate.h"
#import "MasterViewController.h"
#interface StartMenuViewController ()
#end
#implementation StartMenuViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}
-(IBAction)showStrainView:(id)sender{
AppDelegate *delegate = nil;
delegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
MasterViewController *addStrainView = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
[delegate swapView:self.view toView:addStrainView.view];
}
#end
here is the StartMenuViewController.h
#import <Cocoa/Cocoa.h>
#interface StartMenuViewController : NSViewController
#property (weak) IBOutlet NSButton *showStrainViewButton;
#end
Here is the AppDelegate.h
#import <Cocoa/Cocoa.h>
#class loginView, MasterViewController,StartMenuViewController;
#interface AppDelegate : NSObject <NSApplicationDelegate>{
loginView *loginView;
MasterViewController *masterViewController;
}
#property (assign) IBOutlet NSWindow *window;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
#property (strong) loginView *loginView;
#property (strong) MasterViewController *masterViewController;
#property (strong) StartMenuViewController *starMenuViewController;
-(void)swapView:(NSView *)view1 toView:(NSView *)view2;
#end
Here is the AppDelegate.m
#import "AppDelegate.h"
#include "MasterViewController.h"
#import "ScaryBugDoc.h"
#import "Strains.h"
#import "loginView.h"
#interface AppDelegate()
#end
#implementation AppDelegate
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
#synthesize loginView;
#synthesize masterViewController;
#synthesize starMenuViewController;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// 1. Create the master View Controller
self.loginView = [[loginView alloc] initWithNibName:#"loginView" bundle:nil];
// 2. Add the view controller to the Window's content view
[self.window.contentView addSubview:self.loginView.view];
self.loginView.view.frame = ((NSView*)self.window.contentView).bounds;
}
-(void)swapView:(NSView *)view1 toView:(NSView *)view2{
//[view1 removeFromSuperview];
[self.window.contentView addSubview:view2];
view2.frame = ((NSView*)self.window.contentView).bounds;
}
#end
If you need the loginView.h and loginView.m files I can add them as well. I would appreciate any and all help. Thanks in advance
The problem is here:
MasterViewController *addStrainView = [[MasterViewController alloc]initWithNibName:#"MasterViewController" bundle:nil];
[delegate swapView:self.view toView:addStrainView.view];
You don't keep a reference to the MasterViewController so it gets deallocated even though its view is kept around. Now anytime the view tries to access methods from the view controller, things fail.
You should make addStrainView a child view controller of self in the above code so the view controller sticks around as long as its view.
I have searched stackoverflow for similar problems and have found some, but they did not resolve my problem. I have 3 textfields (name,address,phone) from which I want to get the text. I have declared them in the (.h) file, also the #property, and then #synthesized them in the (.m) file. I have a IBAction for a button declared in the (.h) file and linked up correctly. Now when I push this button I want to get the values from the textfields but NSLog shows they are all (null) even before I do anything with the textfields. Its very simple code, i can't understand why it returns null.
//CoreDataViewController.h
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
#property (strong, retain) IBOutlet UITextField *name;
#property (strong, retain) IBOutlet UITextField *address;
#property (strong, retain) IBOutlet UITextField *phone;
#property (strong, retain) IBOutlet UILabel *status;
- (IBAction) saveData;
#end
//CoreDataViewController.m
#import "coreDataViewController.h"
#import "AppDelegate.h"
#implementation coreDataViewController
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;
- (void) saveData
{
NSLog(#"Name %# Address %# Phone %#",self.name.text,self.address.text,self.phone.text);
...some more code (commented out)....
}
IMO you have incorrectly synthesized iVars.
You use syntax:
synthesize name=_name;
but in the .h file you have:
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
Change this part to:
#interface coreDataViewController : UIViewController {
UITextField *_name;
UITextField *_address;
UITextField *_phone;
UILabel *_status;
}
Just change below code
write synthesize like this
#synthesize name;
#synthesize phone;
#synthesize address;
#synthesize status;
ratherthen
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;
I am trying to improve myself in Objective-C and what I am on about is now modifying and changing and existed project. I did everything I wanted expect one thing. Theres an info button in my program and it doesnt related with .xib file. I tried to remove it but always my main.m gave error like SIGABRT (int retval thing.)
Here is the thing what I want to modify
http://i.stack.imgur.com/ZG51s.png // The picture of my program and info button
I am trying to remove the (i) button on the right-down corner.
Here's my code
This is my RootViewController.h
#import <UIKit/UIKit.h>
#class MainViewController;
#interface RootViewController : UIViewController {
IBOutlet UIButton *infoButton; //Silinecek
MainViewController *mainViewController;
}
#property (nonatomic, retain) MainViewController *mainViewController;
#end
This is my RootViewController.m
#import "RootViewController.h"
#import "MainViewController.h"
#implementation RootViewController
#synthesize mainViewController;
- (void)viewDidLoad {
MainViewController *viewController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
self.mainViewController = viewController;
[viewController release];
[self.view insertSubview:mainViewController.view belowSubview:infoButton];
}
and also I tried to modify my AppDelegate h and m. Here they are ;
#import <UIKit/UIKit.h>
#class RootViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet RootViewController *rootViewController;
}
#property (nonatomic, retain) UIWindow *window;
#property (nonatomic, retain) RootViewController *rootViewController;
#end
#import "AppDelegate.h"
#import "RootViewController.h"
#implementation AppDelegate
#synthesize window;
#synthesize rootViewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[rootViewController view]];
//[window makeKeyAndVisible];
}
/*
- (void)dealloc {
[rootViewController release];
[window release];
[super dealloc];
}
*/
What should I do for removing that info button in my View. Thanks for the any tips
And if you are interested in this is the whole algorithm : http://pastebin.com/hHQkQYS6
Do you still have the control linked somewhere in your xib file? It is declared as an IBOutlet control. Usually when I have these controls I will use the GUI link this control in some way (I can't remember what exactly as I have not done Obj-C in a long time). But I would definitely have a look around you xib file (as well as removing [self.view insertSubview:mainViewController.view belowSubview:infoButton];
The exception mentions:
[<RootViewController 0x4b9ab20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key infoButton.
The call stack shows that it is thrown by UINib. So this is happening during nib load. So check for all objects present, carefully, in the nib and remove the info button
I have the following code:
//RootViewController.h:
#import <UIKit/UIKit.h>
#interface RootViewController : UIViewController{
IBOutlet UITextField *login_uname;
IBOutlet UITextField *login_pword;
IBOutlet UIActivityIndicatorView *login_thinger;
IBOutlet UIImageView *logo;
IBOutlet UISwitch *login_remember;
IBOutlet UIScrollView *scrollView;
}
-(IBAction) login_submitClick:(id)sender;
-(IBAction) doneEditing:(id)sender;
-(IBAction) clearPword:(id)sender;
-(void) showSignUp:(id)sender;
-(void)doLogout:(id)sender;
//for file handling:
-(NSString *)documentsPath;
-(NSString *)readFromFile:(NSString *)filePath;
-(void) writeToFile:(NSString *)text withFileName:(NSString *) filePath;
#end
//RootViewController.m
#import "RootViewController.h"
//#import "Main.h"
//#import "SignUp.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "CommonCrypto/CommonHMAC.h"
#import "Details.h"
//#import "signUpSMS.h"
#import "JSON.h"
#implementation PrestoCab3ViewController
#synthesize login_uname; //this line throws the error in the title
...
I'm using XCode 4.1 and was wondering if someone could please help me get to the bottom of this error. I'm very new to XCode.
Many thanks in advance,
You need to declare the property with #property in your interface.
#property( nonatomic, retain ) IBOutlet UITextField * login_uname;
Here, non-atomic is used because it's an IBOutlet.
Also note the property has the retain modifier, meaning you are responsible to release the object when you don't need it anymore.
Why am I getting the above compilation error in all of my source files after creating editing this file:
#import <UIKit/UIKit.h>
#protocol FlipsideViewControllerDelegate;
#interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
UITextField *textField;
}
#property (nonatomic, retain) IBOutlet UITextField *textField;
#property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
-(IBAction) textChanged:(id) sender;
After editing my flipsidecontroller.h to look like this. I get the error in all of my other source files. Like this one:
// MainViewController.h
// MVC
//
// Created by Nick Martin on 3/31/11.
// Copyright 2011 Nick. All rights reserved.
//
#import "FlipsideViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
UILabel *label;
}
#property (nonatomic, retain) IBOutlet UILabel *label;
- (IBAction)showInfo:(id)sender;
#end
It is complaining about the interface declaration for each of my controllers???
Thanks in advance for the help!
Update - put the textChanged event into the interface
// FlipsideViewController.h
// MVC
//
// Created by Nick Martin on 3/31/11.
// Copyright 2011 Nick Martin. All rights reserved.
//
#import <UIKit/UIKit.h>
#protocol FlipsideViewControllerDelegate;
#interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
UITextField *textField;
}
#property (nonatomic, retain) IBOutlet UITextField *textField;
#property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
-(IBAction) textChanged:(id) sender; //DOH!!!
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
Your textChanged: method isn't in an interface or protocol. Did you mean to include it in FlipsideViewController or FlipsideViewControllerDelegate?
You have this:
-(IBAction) textChanged:(id) sender;
but it seems to have fallen outside of your #protocol after the #end.