2013-08-25 42 views
0

我有一個包含不同組件的程序,但是當我編譯時,我每次都得到SIGBART信號。我的代碼的主要目的是在用戶移動時更改布爾值,輕按按鈕時將文本設置爲變量,並將字符串設置爲/不按下不同按鈕。我的代碼如下:XCode iOS中的錯誤SIGBART

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 
+0

你的代碼在哪裏出現'SIGABRT'? – bdesham

回答

0

難道你不希望把這個東西:

NSString *on; 
BOOL move= FALSE; 
NSString *content; 

@interface@end之間在.h文件中?

不要忘記:每個屬性的@property (nonatomic, strong)(BOOL值沒有強參數)。

你的界面應該是這樣的:

#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 
+0

這些是全局變量,這應該是一個評論。 – CodaFi

+0

所以,你做錯了。 http://stackoverflow.com/questions/8808159/objective-c-global-variables –

+0

我仍然得到SIGBART – BobRon

0

在iOS系統/ Objective-C中,變量應該聲明如下如下方式:

@interface類名:超類

{

  • #Declare變量here

}

  • 這裏

  • 變量設置屬性這裏

@end

申報方法和您聲明上面的類聲明的變量。

此外,您還沒有爲applicationdidFinishLaunching方法中的應用程序初始化窗口。試試這個,並設置窗口rootviewcontroller與你想加載的視圖。

+0

我認爲他使用故事板..所以這不是問題。 –