1
我用userInfo做了一个通知我想用另一种格式的另一种方法调用。 有没有办法从[aNotification userInfo]中检索字符串并对其进行修改? userInfo格式如下: { action =“我想使用的字符串”; } 我确实喜欢这样(并且它几乎可以正常工作),但我觉得还有更好的方法来做同样的事情。Xcode从NSNotification中检索userInfo
[[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);
}
谢谢,我是新来的目标c和Xcode :) – kahuna 2013-04-09 21:32:29