0
我尝试在dictionnary(通过槽观察员)搜索:与dictionnary和label.text未捕获的异常
NSDictionary *myDictionnary = [NSDictionary dictionaryWithObjectsAndKeys:@"details",@"details de l'installation",@"recapitulatif",@"recapitulatif de l'installe",nil];
...设置在标签中的文本:
NSLog(@"key: %@, value: %@", recapitulatif, [dictionnary objectForKey:@"recapitulatif"]);
details.text = [dictionnary objectForKey:@"recapitulatif"];
但它使我未捕获的异常:
-[ThirdViewController objectForKey:]: unrecognized selector sent to instance 0x4b59c30
2012-01-09 15:07:13.179 emars[8185:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ThirdViewController objectForKey:]: unrecognized selector sent to instance 0x4b59c30'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fb45a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01108313 objc_exception_throw + 44
2 CoreFoundation 0x00fb60bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f25966 ___forwarding___ + 966
4 CoreFoundation 0x00f25522 _CF_forwarding_prep_0 + 50
5 emars 0x0000439d -[FirstViewController updateLabel:] + 134
6 Foundation 0x0002f669 _nsnote_callback + 145
7 CoreFoundation 0x00f8c9f9 __CFXNotificationPost_old + 745
8 CoreFoundation 0x00f0b93a _CFXNotificationPostNotification + 186
9 Foundation 0x0002520e -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
10 emars 0x0000880b -[ThirdViewController connectionDidFinishLoading:] + 541
感谢帮助我,我不明白我的错误
编辑:
这里是整个方法:
- (void)updateLabel:(NSNotification*)notification
{
NSDictionary *dictionnary = (NSDictionary*)[notification object];
NSLog(@"key: %@, value: %@", recapitulatif, [dictionnary objectForKey:@"recapitulatif"]);
}
和观察者距离 “ThirdViewController” 级送:
NSDictionary *myDictionnary = [NSDictionary dictionaryWithObjectsAndKeys:@"details",@"details de l'installation",@"recapitulatif",@"recapitulatif de l'installe",nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"LABELUPDATENOTIFICATION" object:self userInfo:myDictionnary];
再次感谢!
编辑2:
- (void)updateLabel:(NSNotification*)notification
{
NSDictionary *dictionnary = (NSDictionary*)[notification userInfo];
NSLog(@"key: %@, value: %@", recapitulatif, [dictionnary objectForKey:@"recapitulatif"]);
NSLog(@"text: ", [dictionnary objectForKey:@"recapitulatif"]);
}
给我
key: <UILabel: 0x4b2ff80; frame = (20 245; 280 133); text = 'Index du Compteur: 1 572,...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x4b30040>>, value: (null)
和
text:
这应该给我@ “recapitulatif DE L'installe”,是不是?
OK THAKS,事实上,我必须在一个观察者中传递多个值,所以我在ThirdViewController类中做了一个字典(正如你所说的),然后通过Observer传递它。我抓住了它,我做了objectforkey(请检查最初的帖子) – clement 2012-01-09 14:32:33
是的,就像我预期的那样..你分配的是错误的。我正在为你更新我的答案。 – 2012-01-09 14:34:52
再次感谢,但我不明白它如何帮助我。使用你的代码我已经获得了有关应用程序的信息,但是我需要从另一个类的myDictionnary中获取激活的值: -/ – clement 2012-01-09 14:53:39