我想在我的表格视图重新加载时恢复复选标记,当我单击表格视图时添加复选标记,当我单击第二个单元格时,旧的检查被删除,现在工作正常我的问题是,当我的表格视图是重新加载旧复选标记应出现在单元格上。谢谢
#import "mapMenuVC.h"
#import "ViewController.h"
#import "AppDelegate.h"
@interface mapMenuVC ()
@end
@implementation mapMenuVC
@synthesize checkedIndexPath;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
dataArray = [[NSMutableArray alloc]initWithObjects:@"Street Map",@"Satellite View",@"Hybird", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [dataArray 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];
}
if([checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0];
cell.textLabel.text = [dataArray objectAtIndex:[indexPath row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.checkedIndexPath)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self.checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
if([self.checkedIndexPath isEqual:indexPath])
{
self.checkedIndexPath = nil;
}
else
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedIndexPath = indexPath;
}
switch (indexPath.row) {
case 0: {
[APPDELEGATE.viewController.myMapView setMapType:MKMapTypeStandard];
[APPDELEGATE.viewController.popoverController dismissPopoverAnimated:YES];
break;
}
case 1:
{
[APPDELEGATE.viewController.myMapView setMapType:MKMapTypeSatellite];
[APPDELEGATE.viewController.popoverController dismissPopoverAnimated:YES];
break;
}
case 2:
{
[APPDELEGATE.viewController.myMapView setMapType:MKMapTypeHybrid];
[APPDELEGATE.viewController.popoverController dismissPopoverAnimated:YES];
break;
}
default:
break;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end