-2

不明白为什么,一切看起来都很好;(但我没有可见的@interface for Book 在 simplebookmanager.m 中声明选择器“initWithAuthor”我也尝试关闭 Xcode 并再次运行但没有工作

书本.h

#import<Foundation/Foundation.h>

@interface Book : NSObject

@property NSString *author;
@property NSString *titel;
@property NSInteger price;
@property NSString *isbn;
@property NSString *course;

-  (id)initWithAuthor:(NSString *)aAuthor
                titel:(NSString*)aTitel
                price:(NSInteger)aPrice
                 isbn:(NSString*)anIsbn
               course:(NSString*)aCourse;

@结尾

book.m

#import "Book.h"

@implementation Book 

    -(id)initWithAuthor:(NSString *)aAuthor
                  titel:(NSString*)aTitel
                  price:(NSInteger)aPrice
                   isbn:(NSString*)anIsbn
                 course:(NSString*)aCourse {
            self = [super init];

    if (self) {
        _author = [aAuthor copy];
        _titel  = [aTitel copy]; // ???
        _price  = aPrice;
        _isbn   = [anIsbn copy];
        _course = [aCourse copy];
        }
    return self;
    }

@end
------------------------------------------------------------
#import "SimpleBookManager.h"
#import "BookManagerProtocol.h"
#import "Book.h"

@interface SimpleBookManager()

@property NSMutableArray *allBooks;


@end

SimpleBookManager.m

@implementation SimpleBookManager

-(id)init {

    self = [super init];

    if (self) {
        _allBooks = [[NSMutableArray alloc] init];
         Book *b1 = [[Book alloc]initWithAuthor :@"Ben"];  <---- got error in this part


    }
    return self;
}


@end
---------------------------------------------------------
SimpleBookManager.h
#import <Foundation/Foundation.h>
#import "BookManagerProtocol.h"
#import "Book.h"

@interface SimpleBookManager : NSObject<BookManagerProtocol>


@end
4

2 回答 2

1

此处调用的方法:

Book *b1 = [[Book alloc]initWithAuthor :@"Ben"];

和这个方法不一样:

-  (id)initWithAuthor:(NSString *)aAuthor
                titel:(NSString*)aTitel
                price:(NSInteger)aPrice
                 isbn:(NSString*)anIsbn
               course:(NSString*)aCourse;

您需要提供方法的所有参数才能调用正确的方法,从而避免警告。

例如:

Book *b1 = [[Book alloc]initWithAuthor:@"Ben"
                                 titel:@"Ford Escort Haynes Manual"
                                 price:11
                                  isbn:@"AAXXEE22"
                                course:@"Yup"];
于 2013-11-06T13:58:20.023 回答
0

您的:

Book *b1 = [[Book alloc]initWithAuthor :@"Ben"];

应该:

Book *b1 = [[Book alloc]initWithAuthor:@"authorName" titel:@"title" price:123 isbn:@"123" course:@"course"];
于 2013-11-06T14:00:27.217 回答