我有一個基於標籤欄的應用程序,在選項卡上有一個TableViewController
。如何使用NSUserDefaults來存儲行屬性
當我更新我的應用程序時,我向我的Table
添加了一個新行。
我想要做的是存儲我的TableViewController
一行的突出顯示顏色,只要我插入一個新的,至少3個會話。
我知道我必須使用NSUserDefaults
,但是,在哪裏? 我的意思是:我應該把它用於我的rowViewController
(這是一個UIViewController
)還是我的TableViewController
(我有所有的行)?
我怎樣才能將單元格屬性導入UIViewController
(如果在那裏我必須使用NSUserDefaults
)?
我有類似:
- (void) applicationDidFinishLaunching:(NSNotification*) notice {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:cell];
if ([(NSInteger*)[[NSUserDefaults standardUserDefaults] integerForKey:cell] intValue] < 3) {
// render highlighted...
} else {
// render normal
} }
我不能做「導致它的一個UIViewController,對不對?然後在
@interface rowViewController : UIViewController
的.H我應該爲了實現細胞添加的東西,然後設置其屬性(顏色)?
在此先感謝。
我不清楚爲什麼你需要使用NSUserDefaults。它總是一樣的顏色?你需要在應用程序會話之間存儲顏色嗎? – sosborn
我需要使用NSUserDefaults,以便當我添加一個帶有背景顏色的新行(例如黃色)時,它會一直保持黃色3個會話。 – Phillip