ios - 打开另一个 View 并取消后选择的单元格

标签 ios uitableview uiviewcontroller

在我单击一个单元格来编辑对象后,该单元格会打开另一个 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/

相关文章:

android - 如何在 Kotlin/Native 中将 const char* 转换为 KString?

ios - 如何在 Swift 和 iOS 9 中使整个项目的导航栏变黑

iphone - iOS UITableView 不显示

ios - indexPath 不可变? swift

objective-c - removeFromSuperview 处的 EXC_BAD_ACCESS - 使用 ARC

c - iOS:将对象添加为属性监听器时,是否必须在释放对象之前将监听器设置为 "unregister"?

ios - Swift:从现有的导航 Controller (如 Facebook 或 Snapchat)推送新的导航 Controller

ios - 如何在 UITableView 中找到完全可见(完全可见)单元格的索引

ios - 高度从 0 变为默认大小后单元格不显示

objective-c - 可以将现有的 ViewController 与 PerformSegueWithIdentifier 一起使用吗?