0

これが私のセットアップです。radiostations というオブジェクトがあり、callsign、宣言された周波数、amStationInfo という名前の NSMutableArray などの文字列がいくつかあります。ビューコントローラーで、配列にデータを入力するSQLiteデータベースにアクセスします...

radiostations.h

@interface radiostations : NSObject {

    NSString *format;
    NSString *city;
}

@property (nonatomic, retain) NSString *format;
@property (nonatomic, retain) NSString *city;

ViewController.m

radiostations *amStationClass = [[radiostations alloc] init];
NSMutableArray* amStationInfo = [[NSMutableArray alloc] init];

while (sqlite3_step(statement) == SQLITE_ROW)
    {
    NSString *cityField = [[NSString alloc] initWithUTF8String:
                                   (const char *) sqlite3_column_text(statement, 10)];
    NSString *formatField = [[NSString alloc] initWithUTF8String:
                                    (const char *) sqlite3_column_text(statement, 0)];
    [amStationInfo addObject:amStationClass];
                    [amStationClass setCity:cityField];
                    [amStationClass setFormat:formatField];
    }
[tabView reloadData];
sqlite3_finalize(statement);

そして、UITableViewにデータを入力します

NSString *cityValue = [(radiostations *)[amStationInfo objectAtIndex:indexPath.row] city];
NSString *formatValue = [(radiostations *)[amStationInfo objectAtIndex:indexPath.row] format];
cityLabel.text = cityValue;
formatLabel.text = formatValue;

最初はいくつかの配列を扱っていましたが、これはうまくいきました。次に、クラスオブジェクトを使用して1つの配列のみを処理するように変更しましたが、現在は機能していません。私はSQLiteクエリと何が機能しないかを知っているので、問題はありません。配列にデータが取り込まれていないようです。

4

2 に答える 2

2

同じオブジェクトのプロパティを変更し、radiostationsそれを配列に何度も追加しています。radiostationssqliteデータベースから行ごとに新しいオブジェクトを作成し、これを追加する必要があります。

while (...) {
    // fetch data as before

    radiostations *record = [[radiostations alloc] init];
    [record setCity: cityField];
    [record setFormat: formatField];
    [amStationInfo addObject: record];
    [record release];
}

ARCを使用している場合は、線を削除する必要があり[record release];ます。そうでない場合は、これらのオブジェクトのリークを回避する必要があります。

于 2012-04-24T19:20:42.863 に答える
1

mutablearrayをどこに割り当て/初期化しましたか?何かのようなもの:

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

オブジェクトを追加する前に、一度割り当てる必要があります

于 2012-04-24T19:13:22.527 に答える