-2

我已经声明了一个名为 Squad 的属性,但是当我发送 [self getSquad] 时,我得到“SquadViewController 没有可见的@interface 声明选择器'getSquad'”。

SquadViewController.h:

#import "FlipsideViewController.h"
#import "Squad.h"

@interface SquadViewController : UIViewController <FlipsideViewControllerDelegate, UIPopoverControllerDelegate>

@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;

@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;

@property (nonatomic, retain) IBOutlet UILabel *squadNameLabel;

@property Squad *squad;

- (IBAction)updateTitleWithName:(id)sender;

@end

SquadViewController.m:

#import "SquadViewController.h"

@interface SquadViewController ()

@end

@implementation SquadViewController

@synthesize squadNameLabel;
@synthesize squad;

...

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    if (![self getSquad]) //<--THIS IS WHERE THE ERROR IS
    {
        [self setSquad:[Squad squadWithName:@"New Squad"]]; //<-- NOT HERE, SO THE SETTER SEEMS TO EXIST
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

...

我认为“@synthesize小队”会生成getSquad和setSquad,所以我很困惑。

这是 Squad 的代码,如果由于某种原因我不明白它是相关的(我是 Objective C 的新手,我仍然觉得它很混乱(我来自 java 背景)):

小队.h:

#import "SquadBuilderObject.h"

@interface Squad : NSObject

@property NSString *name;

+ (id) squadWithName:(NSString*)name;

@end

分队.m:

#import "Squad.h"

@implementation Squad

@synthesize name;

+ (id)squadWithName:(NSString *)name
{
    Squad *newSquad = [[Squad alloc] init];
    [newSquad setName:name];
    return newSquad;
}

@end
4

1 回答 1

8

一个名为的属性的标准 gettersquadsquad,不是getSquad

“get...”命名法通常保留给通过引用返回的事物(例如- (BOOL)getSquad:(Squad **)outSquad)。

于 2013-06-30T18:13:11.777 回答