![](/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.