2012-01-31 2 views
0

NSNotificationappDelegate에 생성합니다.NSNotification이 셀렉터를 호출하지 않음

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRegister:) name:@"checkRegister" object:nil]; 

    return YES; 
} 

-(void)checkRegister:(NSNotification *) notification{ 

//Some code 

} 

그리고 다른 클래스에 통지를 게시하고있다 :

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"DONE. Received Bytes: %d", [webData length]); 
    NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@",theXML); 
    [theXML release]; 

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData: webData]; 
    [xmlParser setDelegate:self]; 
    [xmlParser setShouldResolveExternalEntities: YES]; 
    [xmlParser parse]; 
    [xmlParser release]; 

    [connection release]; 
    [webData release]; 

    if(strUserName != NULL) 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"checkRegister" object:nil]; 


} 

문제는 checkRegister가 호출되지 않습니다 것입니다.
누군가 나를 도와 줄 수 있습니까?
감사합니다,
Nitish

당신은 통지를 게시하지만, 전에 설정 strUserName 그래서 확실히, NSLog(@"%@", strUserName)을 시도 할 것을 어디가 표시되지 않는 경우 @"checkRegister" 통지의 목적은, 당신이 당신의 if(strUserName != NULL) 체크가 무엇
+0

여기서 'strUserName'이 (가) 설정되어 있습니까? 통지가 게시되는 것을 어떻게 알 수 있습니까? 그 줄에 중단 점을 놓고 전화가 왔는지 확인 했습니까? – user1118321

+0

구문 분석시 설정됩니다. 그것은 문제가되지 않습니다. 메소드 checkRegister를 호출 할 수 없습니다. – Nitish

답변

2

. 나는 그것이 null이라고 확신한다. 그 strUserName이 구문 분석 한 XML 데이터의 것이라면 구현 한 NSXMLParser 대리자 메서드에있는 XML 구문 분석 코드 다음에 알림을 게시해야합니다. 될 것입니다 어떤 one of these you use.

[xmlParser parse] 차단하지 않습니다,

if(strUserName != NULL) 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"checkRegister" object:nil]; 

호출 할 것이다, 그래서 xmlParser 구문 분석을 완료, 그래서 당신의 strUserName 아직 설정되지 않은, 그리고 그것이 전무하고 이유 전에

당신의

을 넣어 : postNoticationName:

EDIT가 호출되지 않습니다 당신의 application:didFinishLaunchingWithOptions:의 바로 위에

2,, 당신이 통지를 등록하기 전에

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRegister:) name:@"checkRegister" object:nil]; 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil] autorelease]; 
    } else { 
     self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil] autorelease]; 
    } 
    self.window.rootViewController = self.mainViewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

이 작동 예를 들어, 기본보기에서 알림을 게시 할 가능성이 높다

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil] autorelease]; 
    } else { 
     self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil] autorelease]; 
    } 
    self.window.rootViewController = self.mainViewController; 
    [self.window makeKeyAndVisible]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRegister:) name:@"checkRegister" object:nil]; 
    return YES; 
} 

동안 데이터로드가 MainControllerViewviewDidLoad 방법으로 완료되면 작동하지 않습니다.

+0

X 슬래시 : 내 요점을 이해하지 못한다. 나는 위젯을 추가하여 같은 클래스에있는 selector에 checkRegister를 추가하고 알림을 만들 때 대리자 호출을 추가합니다. 그러나 선택자는 결코 호출되지 않습니다. 당신이 말하는 것은 또한 정확하지만 나중에 부분입니다. 첫 번째 일은 선택자가 호출되어야한다는 것입니다. strUserName == nil이므로 – Nitish

+0

선택기가 호출되지 않습니다. postNotificationName :이 아직 수행되지 않은 NSXML 위임자에서 설정 했으므로 무효입니다. 당신이 나를 믿지 않는다면, 코드에서 if (strUserName! = NULL)을 제거하십시오. –

+0

나는 그것을 논평했다. 스틸 선택기가 호출되지 않습니다. – Nitish

관련 문제