0

收到此错误:

'NSInvalidArgumentException',原因:'-[EngineerModel _isNaturallyRTL]:无法识别的选择器发送到实例

我已阅读如何解决“无法识别的选择器发送到实例”?和别的。

将 Xcode 4.5.1 与 arc 一起使用(我第一次使用 arc)

这是我的代码,它基于早期的非弧项目,效果很好

数据库.m

// Models for data
#import "EngineerModel.h"

- (NSArray *)returnEngineers
{
    NSMutableArray *retval = [[NSMutableArray alloc] init];

    NSString *query = @"SELECT * FROM engineers";

    stmt = nil;

    if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &stmt, nil) == SQLITE_OK) {
        while (sqlite3_step(stmt) == SQLITE_ROW) {

            char *engineerIDChr =         (char *) sqlite3_column_text(stmt, 0);
            char *engineerNameChr =         (char *) sqlite3_column_text(stmt, 1);
            char *engineerSigFileChr =         (char *) sqlite3_column_text(stmt, 2);
            char *engineerPhoneChr =   (char *) sqlite3_column_text(stmt, 3);
            char *engineerEmailChr =          (char *) sqlite3_column_text(stmt, 4);
            char *engineerRegNoChr =            (char *) sqlite3_column_text(stmt, 5);

            NSString *engineerID = [[NSString alloc] initWithUTF8String:engineerIDChr];
            NSString *engineerName = [[NSString alloc] initWithUTF8String:engineerNameChr];
            NSString *engineerSigFile = [[NSString alloc] initWithUTF8String:engineerSigFileChr];
            NSString *engineerPhone = [[NSString alloc] initWithUTF8String:engineerPhoneChr];
            NSString *engineerEmail = [[NSString alloc] initWithUTF8String:engineerEmailChr];
            NSString *engineerRegNo = [[NSString alloc] initWithUTF8String:engineerRegNoChr];

            EngineerModel *info = [[EngineerModel alloc] initWithUniqueId:engineerID
                                                               engineerName:engineerName
                                                                     engineerSigFile:engineerSigFile
                                                         engineerPhone:engineerPhone
                                                                engineerEmail:engineerEmail
                                                                  engineerRegNo:engineerRegNo];

            [retval addObject:info];            
        }
        sqlite3_finalize(stmt);
    }
    return retval;
}

数据库有两个条目

和模型

//  EngineerModel.h
#import <Foundation/Foundation.h>

@interface EngineerModel : NSObject
{
    NSString *_engineerID;
    NSString *_engineerName;
    NSString *_engineerSigFile;
    NSString *_engineerPhone;
    NSString *_engineerEmail;
    NSString *_engineerRegNo;
}

@property (nonatomic, copy) NSString *engineerID;
@property (nonatomic, copy) NSString *engineerName;
@property (nonatomic, copy) NSString *engineerSigFile;
@property (nonatomic, copy) NSString *engineerPhone;
@property (nonatomic, copy) NSString *engineerEmail;
@property (nonatomic, copy) NSString *engineerRegNo;



- (id)initWithUniqueId:(NSString *)AengineerID
          engineerName:(NSString *)AengineerName
       engineerSigFile:(NSString *)AengineerSigFile
         engineerPhone:(NSString *)AengineerPhone
         engineerEmail:(NSString *)AengineerEmail
         engineerRegNo:(NSString *)AengineerRegNo;

- (id) init;

@end


//  EngineerModel.m
#import "EngineerModel.h"

@interface EngineerModel ()

@end

@implementation EngineerModel

@synthesize engineerID, engineerName, engineerSigFile, engineerPhone, engineerEmail, engineerRegNo;

- (id)initWithUniqueId:(NSString *)AengineerID
          engineerName:(NSString *)AengineerName
       engineerSigFile:(NSString *)AengineerSigFile
         engineerPhone:(NSString *)AengineerPhone
         engineerEmail:(NSString *)AengineerEmail
         engineerRegNo:(NSString *)AengineerRegNo
{

    if ((self = [super init]))
    {
        self.engineerID = AengineerID;
        self.engineerName = AengineerName;
        self.engineerSigFile = AengineerSigFile;
        self.engineerPhone = AengineerPhone;
        self.engineerEmail = AengineerEmail;
        self.engineerRegNo = AengineerRegNo;

     }
    return self;
}

- (id) init {
    self = [super init];
    return self;
}

@end

最后

我已将 -ObjC 和 -all_load 添加到其他链接器标志

添加了@synthesize(我不认为我必须为弧?)

如果我将其简化为

- (id)initWithId:(NSString *)AengineerID
{
    NSLog(@"AengineerID %@",AengineerID);

    if ((self = [super init]))
    {
        self.engineerID = AengineerID;
    }
    return self;
} 

它跟踪 AengineerID 然后崩溃

有任何想法吗?

4

1 回答 1

0

_isNaturallyRTL是一个私有方法NSString。所以不知何故,你有一个EngineerModel实例,其中一些其他代码期待NSString.

您如何处理EngineerModel从该方法返回的对象数组returnEngineers


就像建议一样……像这样自己使用 sqlite3 C API 是令人沮丧的一课。我强烈建议改用FMDB之类的东西。

于 2012-10-17T03:29:24.623 回答