2013-04-09 1 views
1

저는 userInfo로 aNotification을 가졌습니다. 다른 형식으로 다른 메소드를 호출하고 싶습니다. [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); 

} 

답변

3

userInfo은 NSDictionary입니다. 표준 NSDictionary 메서드를 사용하십시오.

NSString *aString = [aNotification.userInfo objectForKey:@"action"]; 
+0

고맙습니다. 객관적인 C와 Xcode에 새로운입니다. :) – kahuna

관련 문제