【发布时间】:2012-06-14 17:10:16
【问题描述】:
我正在尝试从 NSUserDefaults 创建一个 NSMutableArray,以便稍后添加/删除和编辑它
我的代码是
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *ArrayTable = [NSUserDefaults standardUserDefaults];
[ArrayTable setObject:@"One" forKey:@"myArray"];
[ArrayTable setObject:@"Two" forKey:@"myArray"];
[ArrayTable setObject:@"Three" forKey:@"myArray"];
[ArrayTable setObject:@"Four" forKey:@"myArray"];
[ArrayTable setObject:@"Five" forKey:@"myArray"];
[ArrayTable synchronize];
NSMutableArray *array = [[NSMutableArray alloc] init];
array = [ArrayTable objectForKey:@"myArray"];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
当我构建并运行时,什么都没有显示
我用谷歌搜索了它,但没有任何帮助,我确定我不明白该怎么做
我需要的是构建一个包含空数据的tableview的应用程序,使用将填充数据添加/删除/编辑
谁能帮我解释一下
提前谢谢你
【问题讨论】:
-
你到底想做什么?您正在询问有关 NSUserDefaults 的问题,但从您的 cmets 看来,您根本不需要这些首选项。因此,请描述您要解决的实际最终用户问题。
-
我需要构建一个包含空数据的tableview的应用程序,使用将填写数据添加/删除/编辑@abarnert
-
所以它与存储在 NSUserDefaults 中的首选项完全没有关系?您可能需要编辑问题。
标签: objective-c xcode