Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从另一个类访问在一个类中创建的NSMutableDictionary_Iphone_Uitableview_Automatic Ref Counting_Nsmutabledictionary - Fatal编程技术网

Iphone 从另一个类访问在一个类中创建的NSMutableDictionary

Iphone 从另一个类访问在一个类中创建的NSMutableDictionary,iphone,uitableview,automatic-ref-counting,nsmutabledictionary,Iphone,Uitableview,Automatic Ref Counting,Nsmutabledictionary,如果用户在UITableViewCell中检查某些内容,我将使用此方法在NSMutableDictionary*checkDict中进行检查: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([[checkDict objectForKey:[array objectAtIndex:indexPath.row]] isEqualToString

如果用户在UITableViewCell中检查某些内容,我将使用此方法在NSMutableDictionary*checkDict中进行检查:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[checkDict objectForKey:[array objectAtIndex:indexPath.row]] isEqualToString:@"Check"]) {
        [checkDict setObject:@"NOCheck" forKey:[array objectAtIndex:indexPath.row]];
        [table reloadData];
    }
    else 
    {
        [checkDict setObject:@"Check" forKey:[array objectAtIndex:indexPath.row]];
        [table reloadData];
    }
}
在这个类中,我设置了属性:

@property (nonatomic, strong) NSMutableDictionary *checkDict;
我想用checkDict MutableDictionary中设置了“Check”作为对象的视图中的信息填充下一个视图。如何从下一个类访问此可变dict?如果实例化包含上述代码的前一个类,checkDict将为null。我正在使用ARC和故事板。除了以下方法外,还有其他方法可以做到这一点:

[[NSUserDefaults standardUserDefaults]setObject:checkDict forKey:@"CheckDict"];

有多种方式:

  • 您可以
    创建一个通用的实时数据管理器
    ,它将是一个
    单例类
    ,它将保存此词典,您可以使用此单例类在任何地方访问它

  • 在上述方法中,
    可以使用App Delegate存储字典(带有setter/getter),并使用[[UIApplication sharedAppliation]Delegate]对象访问它

  • 创建(alloc/init)视图时,
    可以将此dictionary对象传递给另一个视图。但是对于这种方法,我们应该从我们拥有这个字典的同一个类中创建视图

  • 当您将此字典声明为属性时,
    可以在要访问此字典的视图类
    中创建此类的引用,然后使用类引用访问它

  • 谢谢