我在appDelegate中创建NSNotification
。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不会被调用。
有人可以帮我在这里。
谢谢,
尼蒂什
'strUserName'在哪里设置?你怎么知道通知正在发布?你有没有在这条线上放置一个断点并确认它被调用? – user1118321 2012-01-31 06:19:44
它在解析中设置。这不是问题。我无法调用checkRegister方法。 – Nitish 2012-01-31 06:21:21