- [EngineerModel _isNaturallyRTL]:发送到实例的无法识别的选择器

时间:2012-10-17 03:26:21

标签: iphone objective-c ios5 memory-management automatic-ref-counting

出现此错误:

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

我读过How to resolve 'unrecognized selector sent to instance'?和其他人。

使用带弧的Xcode 4.5.1(我第一次使用弧线)

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

database.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(我觉得我不得不为arc?)

如果我将其简化为

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

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

跟踪AengineerID然后崩溃

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

_isNaturallyRTLNSString上的私有方法。所以你有一个EngineerModel实例,其他一些代码期待NSString

您对从EngineerModel方法返回的returnEngineers个对象数组做了什么?


就像一个推荐......像你这样自己使用sqlite3 C API是一个令人沮丧的教训。我强烈建议您使用类似FMDB的内容。