在我单击一个单元格来编辑对象后,该单元格会打开另一个 VC 来允许编辑,但如果用户单击取消,该单元格仍会被选中,并很快导致问题和崩溃。
单元格编辑:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"addAssignment"])
{
AddEditViewController *addEditController = segue.destinationViewController;
[addEditController setOtherdelegate:self];
}
if ([segue.identifier isEqualToString:@"edit"]) {
UITableViewCell *cell = sender;
AddEditViewController *addEditController = segue.destinationViewController;
[addEditController setOtherdelegate:self];
addEditController.edit = YES;
AssignmentInfo *a = [self.alist objectAtIndex:[self.tableView indexPathForCell:cell].row];
addEditController.assignmentEditing = a;
[self.alist removeObject:a];
[self.tableView reloadData];
NSString *filePath = [self dataFilePath];
[NSKeyedArchiver archiveRootObject:self.alist toFile:filePath];
}
}
按下取消按钮:
- (IBAction)addAssignmentCancelButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
整个项目(如果需要): http://abdelelrafa.com/AssignmentAppTwo.zip
最佳答案
首先你要做的是删除这一行:
[self.alist removeObject:a];
你的下一个:-(void)newAssignment:(AssignmentInfo *)assignment
删除:
[self.tableView reloadData];
并添加:
[self.tableView reloadData];
到 -(void)deletedAssignment:(AssignmentInfo *)assignment
在你的最后:-(void)newAssignment:(AssignmentInfo *)assignment
删除:
NSString *filePath = [self dataFilePath];
[NSKeyedArchiver archiveRootObject:self.alist toFile:filePath];
并添加:
NSString *filePath = [self dataFilePath];
[NSKeyedArchiver archiveRootObject:self.alist toFile:filePath];
到 -(void)deletedAssignment:(AssignmentInfo *)assignment
关于ios - 打开另一个 View 并取消后选择的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19531992/