iphone - 重新加载 View 后如何保存表格复选标记
<p><p>我想在我的表格 View 重新加载时恢复复选标记,当我点击表格 View 时,复选标记被添加,当我点击第二个单元格时,旧的复选标记被删除,现在工作正常我的问题是当我的 tableview 重新加载了旧的复选标记应该出现在单元格上。
谢谢</p>
<pre><code>#import "mapMenuVC.h"
#import "ViewController.h"
#import "AppDelegate.h"
@interface mapMenuVC ()
@end
@implementation mapMenuVC
@synthesize checkedIndexPath;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
;
// Do any additional setup after loading the view from its nib.
dataArray = [initWithObjects:@"Street Map",@"Satellite View",@"Hybird", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
;
if (cell == nil) {
cell = [ initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
if()
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.font = ;
cell.textLabel.text = ];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.checkedIndexPath)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self.checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
if()
{
self.checkedIndexPath = nil;
}
else
{
UITableViewCell* cell = ;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedIndexPath = indexPath;
}
switch (indexPath.row) {
case 0: {
;
;
break;
}
case 1:
{
;
;
break;
}
case 2:
{
;
;
break;
}
default:
break;
}
}
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>请按照以下步骤编写</p>
<p><strong>在 TableViewDidSelectRowAtIndexPath 中</strong></p>
<pre><code> [ setInteger:indexPath.row forKey:@"Checked"];
[ synchronize];
</code></pre>
<p><strong>现在在 CellForRowAtIndexPath 中</strong></p>
<pre><code>if(indexPath.row == [integerForKey:@"Checked"])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
</code></pre>
<p><strong>它只勾选了您选择的最后一个值</strong></p></p>
<p style="font-size: 20px;">关于iphone - 重新加载 View 后如何保存表格复选标记,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13559937/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13559937/
</a>
</p>
页:
[1]