-1

我正在构建一个简单的应用程序 - RadioStations 来使用实例和类方法(Objective C 中为绝对初学者准备的练习之一)。一切正常,没有调试器错误。一旦我在模拟中按下按钮,应用程序就会崩溃。该练习是为 Xcode 4 编写的,我正在运行 3.2,我怀疑,@synthesize丢失但难以添加它。这是我在日志中得到的

23 RadioStations 0x00001d11 开始 + 53 24 ??? 0x00000001 0x0 + 1 “在抛出 'NSException 的实例后调用终止”

感谢您的任何建议!

我的 viewController.m 文件如下

#import "RadioStationsViewController.h"
#import "RadioStation.h"


@implementation RadioStationsViewController


#pragma mark - View lifecycle 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    myStation = [[RadioStation alloc] initWithName:@"STAR 94" 
                                       atFrequency:94.1]; 
}



 // The designated initializer. Override to perform setup that is required before the view is loaded.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 // Custom initialization
 }
 return self;
 }


/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */


/*
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {?>,m
 [super viewDidLoad];
 }
/*


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (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];
}

- (IBAction)buttonClick:(id)sender { 
    [stationName setText:[myStation name]]; 
    [stationFrequency setText:[NSString stringWithFormat:@"%.1f", 
                               [myStation frequency]]]; 
    if (([myStation frequency] >= [RadioStation minFMFrequency]) && 
        ([myStation frequency] <= [RadioStation maxFMFrequency])) { 
        [stationBand setText:@"FM"]; 
    } else { 
        [stationBand setText:@"AM"]; 
    } 
}


@end

声明 .h 如下

#import <UIKit/UIKit.h>


@class RadioStation; 

@interface RadioStationsViewController : UIViewController 
{ 
    RadioStation *myStation; 
    IBOutlet UILabel* stationName; 
    IBOutlet UILabel* stationFrequency; 
    IBOutlet UILabel* stationBand; 

} 

- (IBAction)buttonClick:(id)sender; 



@end
4

0 回答 0