Ios 将永久复选标记添加到tableView单元格

Ios 将永久复选标记添加到tableView单元格,ios,uitableview,checkmark,Ios,Uitableview,Checkmark,my viewController包含一个tableView,用户可以在其中通过coreData添加单元格。 我定义了单元格: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Travel"; UITableViewC

my viewController包含一个tableView,用户可以在其中通过coreData添加单元格。 我定义了单元格:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Travel";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        NSManagedObject *travel = [self.travelling objectAtIndex:indexPath.row];

        UILabel *countryLabel = (UILabel *)[cell viewWithTag:101];
        kategorieLabel.text = [travel valueForKey:@"country"];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(15.0f, 32.0f, 24.0f, 20.0f);
        [cell addSubview:button];

            if ([[travel valueForKey:@"tick"] isEqualToString:@"yes"]) {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else{
        [cell setAccessoryType:UITableViewCellAccessoryNone];
    }
        return cell; 
    }

- (void)buttonTapped:(UIButton *)sender {
    UITableViewCell *owningCell = (UITableViewCell*)[sender superview];
    [owningCell setAccessoryType:UITableViewCellAccessoryCheckmark];
    NSIndexPath *indexPath = [_tableView indexPathForCell:owningCell];
    NSManagedObject *travel = [self.travelling objectAtIndex:indexPath.row];
    [travel setValue:@"yes" forKey:@"tick"];
    }

当用户点击单元格上的按钮时,复选标记应出现。但当我重新加载或重新启动应用程序时,并不是所有的复选标记都在那里。也许有更好的方法可以做到这一点。

你是否存储了
einkauf
(无论是什么)状态/数据?对不起……我已经将其重命名了……它是
travel
,你需要用核心数据保存更改。@Kevin我以为我是用我的las产品线做的code@user2650439您正在设置数据,但未保存数据。我相信你需要根据你的背景来判断。