![](/img/trans.png)
[英]How to use filteredArrayUsingPredicate with NSDictionary?
[英]How to use [self pushControllerWithName:xxx context:NSdictionary]?
使用WatchOS:
在InterfaceContoller.m的(void)session .... didReceiveMessage ...
NSDictionary *request = @{@"testkey":@"testvalue"};
//i've also tried context:[NSNumber numberWithInt:1]
[self pushControllerWithName:@"Controller" context:request];
在Controller.m的-(void)awakeWithContext:(id)context
[super awakeWithContext:context];
NSLog(@"context = %@", context);
我得到context = <InterfaceController: 0x14d80a30>
而不是我设置的NSObject。
我想做的是,在pushController方法中传递一个值,然后Controller.m将检查该值并根据该值执行不同的操作。 我该如何实现?
抱歉,这是我的错误。
我收到了该答复,因为我已经放置了context:self
,并且我使用的是该代码,而不是问题中所述的NSDictionary。
或者,由于context
是ID,因此我们可以通过以下方法检查所需类的ID(NSDictionary,NSString,NSNumber等):
if ([context isKindOfClass:[NSDictionary class]])
//[NSDictionary class] to check for NSDictionary. Use NSString, NSNumber for the one you need etc
{
NSDictionary* dict = (NSDictionary*)context;
NSLog(@"context dict = %@", dict);
}
傻我!
参考: 目标C-如何对ID进行字符串化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.