HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 当用户多次加载视图时,在uitableview上保存附件复选标记大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我实现了一个带有tableview的UIViewController,基本上它作为我的uicollectionview的一组“过滤器”加载.

现在,当我点击tableview中的复选标记时,它会相应地“过滤”我的单元格,但现在当我再次重新加载视图时,我想显示我使用过的最新“复选标记”或“过滤器”.

我已经看到这是用NSUserDefaults实现的,但我无法成功实现它.

如果有人能帮助我,我将不胜感激.

FiltersViewController.m:

#import "FiltersViewController.h"

@interface FiltersViewController ()

@property (nonatomic,strong) NSMutableSet *SELEctedRowObjects;
//@property (nonatomic,strong) NSArray *filters;

@end

@implementation FiltersViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    self.SELEctedRowObjects = [NSMutableSet setWithCapacity:10];
}

- (IBACtion)filteRSSelected:(id)sender {
    [self.delegate filteRSSelected:self.SELEctedRowObjects];
}

- (IBACtion)cancelFilterSELEction:(id)sender {
    [self.delegate filterSELEctionCancelled];
}

- (NSString *)getKeyForIndex:(int)index
{
    return [NSString StringWithFormat:@"KEY%d",index];
}

- (BOOL) getcheckedForIndex:(int)index
{
    if([[[NSUserDefaults standardUserDefaults] valueForKey:[self getKeyForIndex:index]] boolValue]==YES)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (void) checkedCellATindex:(int)index
{
    BOOL @R_618_8338@hecked = [self getcheckedForIndex:index];

    [[NSUserDefaults standardUserDefaults] SETVALue:[NSnumber numberWithBool:!@R_618_8338@hecked] forKey:[self getKeyForIndex:index]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filter" forIndexPath:indexPath];
    cell.textLabel.text = [NSString StringWithFormat:@"%u",indexPath.row];



    return cell;
}

- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath {


    UITableViewCell *cell = [tableView cellForRowATindexPath:indexPath];
    NSString *obj = cell.textLabel.text;

    if (cell.accessoryType == UITableViewCellAccessorycheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        [self.SELEctedRowObjects removeObject:obj];
    }
    else {
        cell.accessoryType = UITableViewCellAccessorycheckmark;
        [self.SELEctedRowObjects addObject:obj];
    }

    [tableView deSELEctRowATindexPath:indexPath animated:YES];

}
@end

解决方法

你还需要检查cellForRowATindexPath.在此编写此代码
if([[NSUserDefaults standardUserDefaults] objectForKey:[self getKeyForIndex:indexPath.row]])
{
    cell.accessoryType = UITableViewCellAccessorycheckmark;
}
else
{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

是的,不要忘记在didSELEctRowATindexPath中调用方法

[self checkedCellATindex:indexPath.row];

请享用.

大佬总结

以上是大佬教程为你收集整理的ios – 当用户多次加载视图时,在uitableview上保存附件复选标记全部内容,希望文章能够帮你解决ios – 当用户多次加载视图时,在uitableview上保存附件复选标记所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。