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