Iphone 从另一个类访问在一个类中创建的NSMutableDictionary
如果用户在UITableViewCell中检查某些内容,我将使用此方法在NSMutableDictionary*checkDict中进行检查: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
-(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]对象访问它
可以将此dictionary对象传递给另一个视图。但是对于这种方法,我们应该从我们拥有这个字典的同一个类中创建视图
可以在要访问此字典的视图类
中创建此类的引用,然后使用类引用访问它