[英]iOS Xcode - Multiple self delegates in single set of h/m files?
I'm a huge noob, let's get that straight. 我是一个大菜鸟,让我们说清楚。
Currently I have in my header file... 目前我的头文件中有...
@interface ViewController : UIViewController <UIWebViewDelegate>
...but can I have multiple delegates in the h/m files? ...但是我可以在h / m文件中有多个代表吗?
Can I add somehow? 我可以添加某种方式吗?
The reason I ask this, is because of a warning I'm getting... 我问这个的原因是因为我收到警告。
"Assigning to 'id' from incompatible type 'ViewController *const __strong'" “从不兼容的类型'ViewController * const __strong'分配给'id'”
The app works fine, but I want to make sure the code is 100% proper. 该应用程序运行正常,但我想确保代码正确100%。
(LONG STORY SHORT, I'm trying to add location tracking to my app, and I did, and it works fine, but it's giving me a warning because I'm 100% positive I didn't implement it properly, as I am trying to have multiple "XXX.delegate = self;" going on. (长话短说,我正在尝试将位置跟踪添加到我的应用程序中,并且确实可以,但它可以给我一个警告,因为我100%肯定我没有正确实施它,因为我尝试进行多次“ XXX.delegate = self;”。
I want to somehow have... 我想以某种方式...
self.locationManager.delegate = self;
AND 和
tapView.delegate = self;
in the same "-(void)viewDidLoad"... 在同一“-(void)viewDidLoad”中...
Again, I expect people to literally say "Wtf are you smoking, you are doing this all wrong", because I am.. I need help. 再一次,我希望人们能从字面上说“ Wtf,你在抽烟,你做错了所有事”,因为我在……我需要帮助。 Please help.
请帮忙。 I've been googling all day.
我整天都在谷歌搜索。
That was a very long winded way of asking how to do this: 这是询问如何执行此操作的漫长方法:
UIViewController <UIWebViewDelegate, UITextFieldDelegate, UITableViewDelegate>
There is no issue in doing this at all. 这样做完全没有问题。 You must specify the protocol to remove the warning
您必须指定协议以删除警告
您可以确认多重播放代表,即
@interface ViewController : UIViewController <UIWebViewDelegate,SomeOtherDelegate>
Well, you can conform to multiple protocols in your .h file like that: 好了,您可以在.h文件中遵循以下多个协议:
@interface ViewController : UIViewController <UIWebViewDelegate, UITableViewDelegate, UITableViewDataSource>
Ad you can also conform to more protocols in your .m file with a private class extension like that: 此外,您还可以在.m文件中使用私有类扩展名来遵循更多协议,例如:
@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
Don't mix them up 不要把它们混在一起
in .h file 在.h文件中
@interface YourControllerClass : UIViewController <UIAlertViewDelegate, UIWebViewDelegate UITextFieldDelegate>
You can add Delegates when ever you need them. 您可以在需要时添加代表。 These Delegates have their methods defined.
这些代表定义了他们的方法。 You can use their methods as you wish
您可以根据需要使用他们的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.