首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode从NSNotification检索userInfo

Xcode从NSNotification检索userInfo
EN

Stack Overflow用户
提问于 2013-04-10 03:27:23
回答 1查看 457关注 0票数 1

我有一个带有userInfo的aNotification,我想用不同的格式调用另一个方法。有没有办法从aNotification userInfo中检索字符串并对其进行修改?userInfo的格式是这样的:{ action =“我想使用的字符串”;}我确实喜欢这样(而且它几乎正常工作),但我觉得有一种更好的方法来做同样的事情。

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playClicked:) name:kNotificationActionTapped object:nil];    

 ..................

-(void)playClicked:(NSNotification *)aNotification {
NSLog(@"Notification=%@", [aNotification userInfo]);

SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];

NSString *jsonString = [jsonWriter stringWithObject:[aNotification userInfo]];

[jsonWriter release];

NSString * string1 =  [jsonString substringFromIndex:11];
NSString * string2 = [string1 substringToIndex:[watch length] -2];


NSLog(@"string=%@", string1);
NSLog(@"string=%@", string2);

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-10 03:32:01

userInfo是一个NSDictionary。使用标准的NSDictionary方法。

代码语言:javascript
复制
NSString *aString = [aNotification.userInfo objectForKey:@"action"];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15910822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档