我有一个带有userInfo的aNotification,我想用不同的格式调用另一个方法。有没有办法从aNotification userInfo中检索字符串并对其进行修改?userInfo的格式是这样的:{ action =“我想使用的字符串”;}我确实喜欢这样(而且它几乎正常工作),但我觉得有一种更好的方法来做同样的事情。
[[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);
}发布于 2013-04-10 03:32:01
userInfo是一个NSDictionary。使用标准的NSDictionary方法。
NSString *aString = [aNotification.userInfo objectForKey:@"action"];https://stackoverflow.com/questions/15910822
复制相似问题