I have created a table view and displayed the datas. When i click the data in the table view, i put the accessory mark (using UITableViewCellAccessoryCheckmark, Like, Check Mark). Now i want to preserve the state of index position. Because when i go to the another class and then come back to the table view, the previous state(accessory mark) will be displayed. SO how can i preserve the state, which means store or save the indexpath value.(Without using AppDelegate method)so How can i achieve this?
Here my sample code is,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (newRow != oldRow)
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:
indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:
checkedData];
oldCell.accessoryType = UITableViewCellAccessoryNone;
checkedData = indexPath;
}
if (newRow == oldRow) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
// cell.accessoryType = UITableViewCellAccessoryNone;
}
checkedData = indexPath;
}
}
When back to the table view class, the previous state should be preserved. so how can i access that?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(checkedData == indexPath) // Doesn't works
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Please help me out.
Thanks