为什么 Xcode 给我这个警告?

发布于 2024-11-09 11:15:55 字数 251 浏览 0 评论 0原文

这是我以编程方式制作 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赠我空喜 2024-11-16 11:15:55

你没有发布警告。但是,我仍然可以假设它是以下两种可能性之一:

  1. searchBar = [[UISearchBar...] 行上出现警告,说明有关类型的信息。这可能表明 searchBar 未正确定义为 UISearchBar*
  2. 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:

  1. A warning on the line searchBar = [[UISearchBar... saying something about types. This may indicate that searchBar isn't defined correctly as a UISearchBar*.
  2. A warning on the line searchBar.delegate = self, saying something about id<UISearchBarDelegate>. The problem here is that your current class never declared itself as conforming to the UISearchBarDelegate protocol. In this case, you need to amend your @interface declaration like so: @interface MyClass : MySuperclass <UISearchBarDelegate>
明天过后 2024-11-16 11:15:55

您的类是否可能不符合 UISearchBarDelegate ?将您的类声明从 更改为

@interface MyClass : NSObject
...
@end

无论如何

@interface MyClass : NSObject<UISearchBarDelegate>
...
@end

,警告是什么?

Is it maybe your class doesn't conform to UISearchBarDelegate? Change you class declaration from

@interface MyClass : NSObject
...
@end

to

@interface MyClass : NSObject<UISearchBarDelegate>
...
@end

Anyway, what's the warning?

唔猫 2024-11-16 11:15:55

1- @interface YourClassName : 父类 < UISearchBarDelegate、UISearchDisplayDelegate、UIPopoverControllerDelegate、UIAlertViewDelegate>

@property UISearchBar *srchBar;

@end

2-@synthesize srchBar; // 在.m文件中

3- [self.srchBar setDelegate:self]; // 在 vi​​ewDidLoad

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文