我在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