Error SIGBART in XCode iOS - iphone

I have a program with different components, but when I compile, I get signal SIGBART every time. The main purpose of my code is to change a boolean when the user moves, set text to a variable when a button is tapped, and set a string to do/don't with the press of different buttons. My code is below:
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize mapView;
#synthesize dodont;
#synthesize reminders;
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation = YES;
on = #"don't";
dodont.text = on;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)mapView:(MKMapView *)mapView
didUpdateUserLocation:
(MKUserLocation *)userLocation
{
move = TRUE;
}
- (IBAction)enable:(id)sender {
on = #"do";
}
- (IBAction)disable:(id)sender {
on = #"don't";
}
- (IBAction)save:(id)sender {
content = reminders.text;
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
NSString *on;
BOOL move= FALSE;
NSString *content;
#interface ViewController : UIViewController {
MKMapView *mapview;
}
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
- (IBAction)enable:(id)sender;
- (IBAction)disable:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *dodont;
- (IBAction)save:(id)sender;
#property (strong, nonatomic) IBOutlet UITextView *reminders;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end

Don't you want to put this stuff:
NSString *on;
BOOL move= FALSE;
NSString *content;
between #interface and #end in your .h file?
And don't forget for: #property (nonatomic, strong) for each property (BOOL value have no strong parameter).
Your interface should look like this:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController {
MKMapView *mapview;
}
#property (strong, nonatomic) NSString *on;
#property (nonatomic) BOOL move;
#property (strong, nonatomic) NSString *content;
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (strong, nonatomic) IBOutlet UITextView *reminders;
#property (weak, nonatomic) IBOutlet UILabel *dodont;
- (IBAction)enable:(id)sender;
- (IBAction)disable:(id)sender;
- (IBAction)save:(id)sender;
#end

In iOS/Objective-C, variables should be declared like below given way :
#interface Classname:SuperClass
{
#Declare variables here
}
Set property for variables here
declare methods here
#end
And you are declaring the variables above the class declarations.
Also you haven't initialized the window for the application in applicationdidFinishLaunching method. Try this and setting the window rootviewcontroller with the view you want to load.

Related

Adding AppDelegate.h and AppDelegate.m info in Swift

Hi I am just starting in swift and taking an iPad app and creating a iphone version.
I am trying to add annotations to a map in Swift and need to add so info to AppDelegate.h and .m to get it to work but in Swift there are is no AppDelegate.h or .m . How do I get this to work?
Here is what has to go into the AppDelegates
.h
#import <UIKit/UIKit.h>
#class AnnotationViewController;
#interface AnnotationAppDelegate : NSObject <UIApplicationDelegate> {
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet AnnotationViewController *viewController;
#end
.m
#import "AnnotationAppDelegate.h"
#import "AnnotationViewController.h"
#implementation AnnotationAppDelegate
#synthesize window=_window;
#synthesize viewController=_viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Please Help..Under tight deadline Thanks.

Using AppDelegate for global readonly data

I have a project on iPhone with iOS4.
A instance variable of app delegate is a dictionary with global readonly data loaded from a plist when app starts.
CalculatorAppDelegate.h
#import <UIKit/UIKit.h>
#class MainViewController;
#interface CalculatorAppDelegate : NSObject <UIApplicationDelegate> {
NSDictionary *RGBSpacesDictionary;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain, readonly) NSDictionary *RGBSpacesDictionary;
#property (nonatomic, retain) IBOutlet MainViewController *mainViewController;
#end
CalculatorAppDelegate.m
#import "CalculatorAppDelegate.h"
#import "MainViewController.h"
#implementation CalculatorAppDelegate
#synthesize mainViewController=_mainViewController;
#synthesize RGBSpacesDictionary;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// load plist
NSString* plistPath1 = [[NSBundle mainBundle] pathForResource:#"RGBSpaces" ofType:#"plist"];
RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];
etc.
}
Then in MainViewController i am able to successfully reading the dictionary in viewDidLoad
MainViewController.h
#class CalculatorAppDelegate;
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
CalculatorAppDelegate *appDelegate;
}
#property (nonatomic, retain) CalculatorAppDelegate *appDelegate;
etc.
}
MainViewCOntroller.m
#import "CalculatorAppDelegate.h"
#implementation MainViewController
#synthesize appDelegate;
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = [[UIApplication sharedApplication] delegate];
RGBSpacesCount = (int) [appDelegate.RGBSpacesDictionary count];
}
In viewDidLoad it is all OK, I can read my dictionary as appDelegate.REGSpaceDictionary.
The problem is with another method of MainVievController called when a button is pressed
- (IBAction) RGBSpaceButtonPressed {
NSLog(#"appDelegate.RGBSpacesDictionary %#", appDelegate.RGBSpacesDictionary);
etc.
}
At this time calling the dictionary (for example with a NSLog) return in a crash.
Can someone help me? Thank you.
In this line
RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];
you are assigning an autoreleased object straight to the ivar so there is no guarantee how long it will stay around for. You should be assigning a non autoreleased object or going through the setter
// Going through the setter
self.RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];
// OR
// Non assigning a non autoreleased object
RGBSpacesDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
To use the setter you would have to redeclare the property in an extension at the top of the app delegate's .m file like this
#interface CalculatorAppDelegate ()
#property (nonatomic, retain, readwrite) NSDictionary *RGBSpacesDictionary;
#end
...
The rest of your implementation
Try to retain the dictionary in app delegate. It must be deallocated at some point, because you get an autoreleased one and you didn't use the property to set it.
// here you must retain the dictionary
[[NSDictionary dictionaryWithContentsOfFile:plistPath1] retain];
Of course don't forget to release it later in dealloc.

Having trouble hooking up instance variables to AppDelegate

Am having some trouble hooking up instance variables in the visual object editor using Xcode4.
Have been able to connect the Whereami App Delegate to the mapView and activityIndicator, but for some reason, can't find the locationTitleField. Am also having trouble connecting the delegates back to the App Delegate.
What am I doing wrong?
Here is the code for Whereami App Delegate.h:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface WhereamiAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate> {
UIWindow *window;
CLLocationManager *locationManager;
IBOutlet MKMapView *mapView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextView *locationTitleField;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
Whereami App Delegate.m
#import "WhereamiAppDelegate.h"
#implementation WhereamiAppDelegate
#synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//-- Create location manager object --
locationManager = [[CLLocationManager alloc] init];
//-- Make this instance of WhereamiAppDelegate the delegate
//-- It will sends its messages to our Whereami delegate.
[locationManager setDelegate:self];
//-- We want all results from the location manager--
[locationManager setDistanceFilter:kCLDistanceFilterNone];
//-- And we want it to be as accurate as possible--
//-- Regardless of how much time/power it takes --
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//-- Tell our location manager to start looking for its location
//-- immediately
[locationManager startUpdatingLocation];
[self.window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(#"Could not find location: %#", error);
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(#"%#", newLocation);
}
Try making them properties instead of iVars ...
#interface WhereamiAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate>
#property (nonatomic, retain) IBOutlet CLLocationManager *locationManager;
#property (nonatomic, retain) IBOutlet MKMapView *mapView;
#property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
#property (nonatomic, retain) IBOutlet UITextView *locationTitleField;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
and don't forget to synthesize them
#synthesize locationManager = _locationManager;
#synthesize mapView = _mapView;
#synthesize activityIndicator = _activityIndicator;
#synthesize locationTitleField = _locationTitleField;
I never use iVars for objects that appear in nib files; I tend to always use properties and have never experienced any issues with hooking up the outlets.

Undeclared Error and iPhone Simulator Crashing

Here's my code:
delegate.h
#import <UIKit/UIKit.h>
#class _4_Control_FunViewController;
#interface _4_Control_FunAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
_4_Control_FunViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet _4_Control_FunViewController *viewController;
#end
delegate.m:
#import "_4_Control_FunAppDelegate.h"
#import "_4_Control_FunViewController.h"
#implementation _4_Control_FunAppDelegate
#synthesize window;
#synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}
- (void)dealloc {
[viewController release];
[window release];
[nameField release];
[numberField release];
[super dealloc];
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface _4_Control_FunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
#property (nonatomic, retain) IBOutlet UITextField *nameField;
#property (nonatomic, retain) IBOutlet UITextField *numberField;
#end
ViewController.m
#import "_4_Control_FunViewController.h"
#implementation _4_Control_FunViewController
#synthesize nameField;
#synthesize numberField;
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
This is what I'm trying to get:
This is what I'm getting:
Looks like it "should" work, but based on your screenshot, I'd say you haven't got things connected correctly in Interface Builder.
Go to Interface Builder and make sure they are hooked up. Where ever you have an IBOutlet declared in a header file, that needs to be hooked up to the corresponding UI object in Interface Builder.
You also have some redundant code (shown below). They are not causing problems, but they double up because you have them declared as properties at the bottom your .h file. You can delete the lines below from your headers, but make sure you leave their corresponding #property declarations in place.
UIWindow *window;
_4_Control_FunViewController *viewController;
UITextField *nameField;
UITextField *numberField;

Loading a new view before the old one iphone sdk

Probably just a simple question, but ive been building a little puzzle game and no decided i could do with a menu for it. Ive created the menu no problem i just cant get it to show before the puzzle. Ive tried changing the code in the appdelegate but its not liking it.
slider appdelegate.h
#import <UIKit/UIKit.h>
#class SliderViewController;
#class MainMenu;
#interface SliderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainMenu *viewController1;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet SliderViewController *viewController;
#property (nonatomic, retain) IBOutlet MainMenu *viewController1;
#end
Slider appdelegate.m
#import "SliderAppDelegate.h"
#import "SliderViewController.h"
#implementation SliderAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize viewController1;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController1.view];
[self.window makeKeyAndVisible];
return YES;
}
But doing that throws out an error:
error: request for member 'view' in
something not a structure or union
I know its probably a stupid question but could anyone help please.
You need to import that class and make alloc the object first see this
Slider appdelegate.m
#import "SliderAppDelegate.h"
#import "SliderViewController.h"
#import "MainMenu.h"//change here
#implementation SliderAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize viewController1;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[[MainMenu alloc] initWithNibName#"MainMenu" bundle:nil] autorelease]; // and here
[self.window addSubview:viewController1.view];
[self.window makeKeyAndVisible];
return YES;
}