2

我想知道是否有办法将像 UITableViewStylePlain 这样的常量传递给 NSDictionary。

我使用 NSValue 传递值类型,如下所示:

CGRect myRec = CGRectMake(0,0,320,568);
NSDictionary *myDic = @{@"val":[NSValue valueWithCGRect:myRec]};
CGRect yourRec = [[myDic valueForKey:@"val"] CGRectValue];

我的问题是如何为 UITableViewStylePlain 之类的常量执行此操作?像这样的东西:

NSDictionary *myDic = @{@"style":[NSValue value:UITableViewStylePlain withObjCType:enum]};

我意识到 enum 不是 ObjectiveC 类型... :(

4

2 回答 2

3

enum通常保持NSInteger(有时NSUInteger),因此在NSNumber这种情况下也可以足够好,例如:

NSDictionary * myDic = @{ @"style" : @(UITableViewStylePlain) };
于 2014-07-20T07:33:16.647 回答
2

枚举值是数字,因此您可以使用NSNumber它们将它们存储在字典中:

NSDictionary *myDic = @{@"style":@[NSNumber numberWithInt:UITableViewStylePlain]};
于 2014-07-20T07:33:01.627 回答