我有一個簡單的問題:我的用戶可以在UIView
中添加按鈕。我將使用NSUserDefault
來保存各種按鈕,然後在應用程序啓動時(不是後臺)將它們重新加載到UIView
中。我該怎麼辦?如何保存/重新載入UIView中的各個按鈕
-(void)AddButton:(UIButton*)sender {
CountButton++;
if (CountButton< 11) {
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(20, 80, 120, 80);
UIImage *buttonImage = [UIImage imageNamed:@"image"];
[button2 setBackgroundImage:buttonImage forState:UIControlStateNormal];
NSString* buttonTitle = [NSString stringWithFormat:@"Button%d", CountButton];
[button2 setTitle:buttonTitle forState:UIControlStateNormal];
NSString *selectorName = [NSString stringWithFormat:@"ButtonAdd%d:", CountButton];
[button2 addTarget:self action:NSSelectorFromString(selectorName)forControlEvents:UIControlEventTouchUpInside];
}}
這是不非常清楚你想要什麼。你想知道如何使用NSUserDefault?另一件事,請儘量讓你的代碼更清晰(正確縮進)... – DrDev
我可以在我的uiview上通過AddButton創建10個不同的按鈕。當我再次關閉我的應用程序時,10個按鈕消失。那麼我的用戶被迫重新創建10個按鈕。 如何保存從我的用戶創建的按鈕? – user2244770
檢查我的答案或sangony的答案..兩者都會爲你工作 – DrDev