1

アプリケーションで「n」個の UIView オブジェクトを動的に作成しています。これらのオブジェクトを画面内の任意の位置にドラッグ アンド ドロップして、プロパティの一部を変更できます。これらすべての詳細を永続ストレージに保存したいと考えています。 、アプリケーションのネスト時間を起動するたびに、作成済みのオブジェクトを表示できるようにします。

それで、これに対する最善の解決策は何ですか?

また、このフォームで参照できるサンプルアプリケーションはありますか?

4

1 に答える 1

0

このようにできると思います。

// Create an array to store the properties
NSMutableArray *viewProperties = [NSMutableArray array]; 

// Loop through all the views
for (UIView *view in views) {

    // Create a dictionary for each view
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    // Store the properties in the dictionary
    [dict setValue:NSStringFromCGRect(view.frame) forKey:@"ViewFrame"];
    ...

    // Add the dictionary to the array
    [viewProperties addObject:dict];
}

// Finally add the array to persistence
[userDefaults setValue:viewProperties forKey:@"ViewProperties"];

後で永続性から配列を取得し、プロパティを使用してビューを作成できます。

NSMutableArray *viewProperties = [userDefaults valueForKey:@"ViewProperties"]; 

for (NSDictionary *dict in viewProperties) {

    UIView *view = [[UIView alloc] init];
    NSString *frameAsString = [dict valueForKey:@"ViewFrame"];
    view.frame = CGRectFromString(frameAsString);
    // Get other properties from dictionary and set it to view
}
于 2011-09-23T06:37:40.607 に答える