XCode编译器警告:'foo'可能不会响应到-bar
问题描述:
我试图让我的头绕着iPhone的Objective-C。到目前为止,我的应用程序正在编译并运行良好,但是我收到了编译器警告,我无法摆脱。XCode编译器警告:'foo'可能不会响应到-bar
报头为:一类:(剪断)
@interface PersonDetailViewController : UIViewController {
NSDictionary *person;
}
@property (retain) NSDictionary *person;
@end
实现这个类:(也剪断)
#import "PersonDetailViewController.h"
@implementation PersonDetailViewController
@synthesize person;
@end
我创造PersonListViewController的PersonDetailViewController的实例,并美其名曰:
#import "PersonListViewController.h"
#import "Person.h"
#import "PersonDetailViewController.h"
@implementation PersonListViewController
- (IBAction)myMethod:(id)sender {
NSDictionary *person = [[Person alloc] initFromTestArray:[sender tag]];
[personDetailViewController setPerson:person];
[[personDetailViewController person] describe];
}
@end
然后我通知:
warning: 'UIViewController' may not respond to '-setPerson' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
warning: 'UIViewController' may not respond to '-person'
它实际上反应不错,但我无法弄清楚如何安排我的头,使编译器会知道什么会回应...
我已与谷歌的希望...我已经提供了足够的信息,有人可以提供帮助。
谢谢你!
答
显然你有personDetailViewController
宣布为UIViewController
?你可以明确地投下控制器:
[(PersonDetailViewController*)personDetailViewController setPerson:person];
但男孩这是丑陋的。在PersonListViewController
标题中简单地声明personDetailViewController
为PersonDetailViewController
会更好。我希望我说得对,所有的长名都让我有些茫然:)
答
我有点迷茫...... 你为什么这样做:
NSDictionary *person = [[Person alloc] initFromTestArray:[sender tag]];
你声明的人是一个NSDictionary,但init'ing一个Person类... 不应该它是
Person *person = [[Person alloc] initFromTestArray:[sender tag]];
编辑 我没有注意到@property &合成,所以你是正确的那里,是我不好......在接受答案是什么你LO争取!
我同意第一点,但是`person`是他在头文件中声明并在执行过程中合成的属性。 – 2009-07-19 18:04:54
Ahhhh好点。我忘了@synthesize ...我会编辑我的帖子。 – micmoo 2009-07-19 18:13:29