我有以下 NSURLSession 代码
NSURL * url = [NSURL URLWithString:urlString];
HomeViewController* hvc= [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:hvc delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url ];
[dataTask setAccessibilityLabel:@"UserProfiling"];
[dataTask resume];
编译器在这条语句中显示警告:
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:hvc delegateQueue: [NSOperationQueue mainQueue]];
警告是:
Sending 'HomeViewController *' to parameter of incompatible type 'id<NSURLSessionDelegate>'
如何删除此警告?
我已通过书面形式向代表们确认:
@interface ProfileTabView : UIViewController <NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate>
{
}
基本上,我正在调用一个 NSURLSessionDataTask 并且委托(delegate)位于另一个 ViewController 中,如您在上面看到的。
最佳答案
(来自评论,为后人作答。)
HomeViewController 不是您添加了协议(protocol)一致性的类 (ProfileTabView)。
关于ios - 我如何摆脱 iOS 7 Objective-C 中的这个警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24468731/