0

this was working earlier but now it is not because it does not recognize the settings in the first .m file below. I did #import Setting.h but it still does not work. Please help!

Here is the .h file:

#import <UIKit/UIKit.h>
#import "EditNameViewController.h"



@interface SettingsViewController : UIViewController <EditNameDelegate>{

IBOutlet UIButton *froshsched;
IBOutlet UIButton *uppersched;


}

.m file. it says settings and 'settings are undeclared

#import "SettingsViewController.h"
#import "Settings.h"

@interface SettingsViewController ()

@end

@implementation SettingsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    self.title = NSLocalizedString(@"Settings", @"Settings");
    self.tabBarItem.image = [UIImage imageNamed:@"spanner"];        
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

-(IBAction)froshsched{
Settings *settings = [Settings sharedInstance];
settings.timelabelfirst = @"12:35";
settings.timelabelsecond = @"1:25";
[[Settings sharedInstance] save];
}
-(IBAction)uppersched{
Settings *settings = [Settings sharedInstance];
settings.timelabelfirst = @"12:10";
settings.timelabelsecond = @"1:00";
[[Settings sharedInstance] save];
}

-(IBAction)editclass{
EditNameViewController*vc2 = [[EditNameViewController alloc] init];
vc2.delegate = self;
[self presentModalViewController:vc2 animated:YES];
}

-(void)dismiss{
[self dismissModalViewControllerAnimated:YES];
}

@end


-(IBAction)editclass;
-(IBAction)froshsched;
-(IBAction)uppersched;

here is the Settings.h

#import <Foundation/Foundation.h>

@interface Settings : NSObject

@property (nonatomic) NSString *redClassName, *orangeClassName, *yellowClassName,   *greenClassName, *ltblueClassName, *dkblueClassName, *purpleClassName, *pinkClassName,    *timelabelfirst, *timelabelsecond;

+(Settings*)sharedInstance;
-(void)save;

@end

and lastly here is the Settings.m file, I feel like I am missing something simple, thanks

#import "Settings.h"

@implementation Settings

@synthesize redClassName, orangeClassName, yellowClassName, greenClassName, ltblueClassName,  dkblueClassName, purpleClassName, pinkClassName, timelabelfirst, timelabelsecond;

-(id)init{
self = [super init];
if(self){
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    redClassName = [defaults objectForKey:@"kredClass"];
    orangeClassName = [defaults objectForKey:@"korangeClass"];
    yellowClassName = [defaults objectForKey:@"kyellowClass"];
    greenClassName = [defaults objectForKey:@"kgreenClass"];
    ltblueClassName = [defaults objectForKey:@"kltblueClass"];
    dkblueClassName = [defaults objectForKey:@"kdkblueClass"];
    purpleClassName = [defaults objectForKey:@"kpurpleClass"];
    pinkClassName = [defaults objectForKey:@"kpinkClass"];
    timelabelfirst = [defaults objectForKey:@"ktime1"];
    timelabelsecond = [defaults objectForKey:@"ktime2"];
}
return self;
}

+(Settings*)sharedInstance{
static Settings *sharedSettings;
if(!sharedSettings) sharedSettings = [[Settings alloc] init];
return sharedSettings;
}
-(void)save{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:redClassName forKey:@"kredClass"];
[defaults setObject:orangeClassName forKey:@"korangeClass"];
[defaults setObject:yellowClassName forKey:@"kyellowClass"];
[defaults setObject:greenClassName forKey:@"kgreenClass"];
[defaults setObject:ltblueClassName forKey:@"kltblueClass"];
[defaults setObject:dkblueClassName forKey:@"kdkblueClass"];
[defaults setObject:purpleClassName forKey:@"kpurpleClass"];
[defaults setObject:pinkClassName forKey:@"kpinkClass"];
[defaults setObject:timelabelfirst forKey:@"ktime1"];
[defaults setObject:timelabelsecond forKey:@"ktime2"];
[defaults synchronize];
}

@end
4

1 に答える 1

0

EditNameController (デリゲートを含む) が提供されていません。いずれにせよ、上記のすべてのコードをコピーして貼り付け、EditNameController 関連の項目をコメントアウトすることで、すべて正常にコンパイルされました (もちろん、ファイルの下部にあるこれらの行を除いて:

-(IBAction)editclass;
-(IBAction)froshsched;
-(IBAction)uppersched;

また、SettingsViewController.h (コンパイル前に追加したもの) の下部に「@end」も表示されませんでした。

于 2012-07-31T01:49:02.470 に答える