我的项目很大,我不确定是哪个代码段导致了问题,所以我只描述一下问题。我有一个初始视图,它是UITableView.
这个视图有一个navigation bar
,其中一个按钮是一个“ edit
”按钮。按下“编辑”按钮会将您带到一个模态视图控制器,其中还有另一个 UITableView。这UITableView
具有它是一个清单的属性table view
(其中可以选择[选中]或取消选择多个项目。一旦您完成选择项目,它将所选对象的数组保存到NSUserDefault.
现在,您回到原始页面,其中你选择的东西的数组应该显示在UITableView
. 我将提供UITableView
数据的数组更改为从NSUserDefaults
.[tableView reloadData]
什么都没有改变。我真的很感激任何提示。如果你们认为您知道代码的哪一部分让我感到悲伤,请回复,我会发布它。谢谢(顺便说一句,我知道我应该把主要view controller
的delegate
)modal view controllers
。提前致谢。
问问题
114 次
2 回答
1
[[NSUserDefaults standardUserDefaults] synchronize];
在模态视图控制器中进行更改后调用。这将保存更改。
确保每次重新加载表格行时更新单元格内容。
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Bleh *data = (Get your data for this row);
cell.textLabel.text = data.myValue;
cell.imageView.image = data.myImage;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
于 2012-08-18T16:39:12.660 回答
0
当您从方法调用返回时,尝试重新加载您tableview
的viewwillappear
modelviewcontroller
- (void)viewWillAppear:(BOOL)animated{
[yourTableView reloadData];
}
于 2013-09-21T11:23:21.207 回答