简体   繁体   中英

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?

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'"

The app works fine, but I want to make sure the code is 100% proper.

(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.

I want to somehow have...

self.locationManager.delegate = self;

AND

tapView.delegate = self;

in the same "-(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. 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:

@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:

@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate>

Don't mix them up

in .h file

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM