为什么 Xcode 给我这个警告?
这是我以编程方式制作 UISearchBar 的代码
- (void)loadView {
[super loadView];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,30)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
}
here is the code I am making a UISearchBar programmatically
- (void)loadView {
[super loadView];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,30)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你没有发布警告。但是,我仍然可以假设它是以下两种可能性之一:
searchBar = [[UISearchBar...
] 行上出现警告,说明有关类型的信息。这可能表明searchBar
未正确定义为UISearchBar*
。searchBar.delegate = self
行上的警告,说明有关id
的内容。这里的问题是您当前的类从未声明自己符合UISearchBarDelegate
协议。在这种情况下,您需要修改您的@interface
声明,如下所示:@interface MyClass : MySuperclass
You didn't post the warning. However, I can still make an assumption that it's one of the following two possibilities:
searchBar = [[UISearchBar...
saying something about types. This may indicate thatsearchBar
isn't defined correctly as aUISearchBar*
.searchBar.delegate = self
, saying something aboutid<UISearchBarDelegate>
. The problem here is that your current class never declared itself as conforming to theUISearchBarDelegate
protocol. In this case, you need to amend your@interface
declaration like so:@interface MyClass : MySuperclass <UISearchBarDelegate>
您的类是否可能不符合
UISearchBarDelegate
?将您的类声明从 更改为无论如何
,警告是什么?
Is it maybe your class doesn't conform to
UISearchBarDelegate
? Change you class declaration fromto
Anyway, what's the warning?
1- @interface YourClassName : 父类 < UISearchBarDelegate、UISearchDisplayDelegate、UIPopoverControllerDelegate、UIAlertViewDelegate>
@property UISearchBar *srchBar;
@end
2-@synthesize srchBar; // 在.m文件中
3- [self.srchBar setDelegate:self]; // 在 viewDidLoad
4 中- [srchBar resignFirstResponder]; // 这样辞职吧!
1- @interface YourClassName : ParentClass < UISearchBarDelegate, UISearchDisplayDelegate, UIPopoverControllerDelegate, UIAlertViewDelegate>
@property UISearchBar *srchBar;
@end
2- @synthesize srchBar; // in the .m file
3- [self.srchBar setDelegate:self]; // in viewDidLoad
4- [srchBar resignFirstResponder]; // resign THIS WAY!