2012-03-19 9 views
0

私は5つのプロパティで定義されたクラスを持っています。これらのプロパティをNSMutableArray(listOfSites)に配置したいと思います。これは私のコードです:NSMutableArrayにクラスが追加されていません。なぜですか?

FMResultSet *rs = [fmdb executeQuery: @"SELECT SITE_ID, SITE_DESC, DATE FROM SiteData WHERE SITE_ID <> '0'"]; 
while([rs next]) { 
    sArray *sa = [[sArray alloc] init]; 
    sa.sSiteID = [rs stringForColumnIndex:0]; 
    sa.sJobDesc = [rs stringForColumnIndex:1]; 
    sa.sJobDate = [rs stringForColumnIndex:2]; 

    [listOfSites addObject:sa]; // add class object to array 
} 
[fmdb close]; 

sArray(いない配列が、クラスの名前)正しい内容を持っていますが、「のaddObject:SA」のメッセージがクラスにクラスを配置しません。

私は間違っていますか?

UPDATE: "listOfSites" の宣言: "listOfSites" の

@interface slSQLite : NSObject { 

    sqlite3 *dataBase; // declare pointer to database 
    UILabel *status; 
    BOOL newFlag; 
    int siteCount; 
    int seqNbr; 
    NSDate *date; 
    NSString *dbCmd; 
    NSMutableArray *listOfSites; // populated by sqlite 

} 

初期化:

@implementation slAppDelegate { } 

@synthesize window = _window; 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    slSQLite *sqlite = [[slSQLite alloc] init]; // allocate class 
    [sqlite checkForDatabase]; // check for database 

    NSMutableArray *listOfSites = [[NSMutableArray alloc] init]; 

    return YES; 
} 
+1

'listOfSites'が宣言され、初期化されたコードを表示します。 –

+0

合意しました。あなたの質問にlistOfSitesが宣言されていますか? sArray saも漏れています。 saをlistOfSitesに追加した後に、saを解放する必要があります。 –

+0

ダーレン:私はARCを使用しています... – SpokaneDude

答えて

1

あなたはlistOfSitesという名前の2つの異なる変数を使用しています。そこに,,

@interface slSQLite : NSObject { 
    // ... 
    NSMutableArray *listOfSites; // populated by sqlite 
} 

あなたはdidFinishLaunchingWithOptionsである変数listOfSitesを初期化します。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    //... 
    NSMutableArray *listOfSites = [[NSMutableArray alloc] init]; 
    //... 
} 

秒1は、インスタンス変数1がクラスslSQLiteです:最初のものはdidFinishLaunchingWithOptions内のローカル変数でありますslSQLiteにある変数は変更されずに初期化されません。

だからあなたはそれを使用する前に、配列を初期化する必要があります

listOfSites = [[NSMutableArray alloc] init]; 
while([rs next]) { 
    sArray *sa = [[sArray alloc] init]; 
    sa.sSiteID = [rs stringForColumnIndex:0]; 
    sa.sJobDesc = [rs stringForColumnIndex:1]; 
    sa.sJobDate = [rs stringForColumnIndex:2]; 

    [listOfSites addObject:sa]; 
} 
NSLog(@"The array listOfSites contains %d items, listOfSites.count); 

PSを。 saはオブジェクトであり、クラスではありません。クラスsArrayのインスタンスです。

+0

こんにちは:listOfSitesはAppDelegateで初期化されています... – SpokaneDude

+0

sch:コードを追加... "listOfSites"には0個の商品が含まれています – SpokaneDude

+0

sch:私はどこにアプリケーションを配置しましたDidFinishLaunching – SpokaneDude

関連する問題