2015-02-10 116 views
0

我在调用Swift项目的特定方法时遇到问题。这里的ObjC方法签名:Swift在调用中的额外参数

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 

我不能把这个工作作为XCode中不断告诉我“额外的参数‘placeholderImage’呼叫”

self.lastLookImageView.setImageWithURL(url, 
    placeholderImage: nil, 
    options: SDWebImageRefreshCached, 
    completed: { 
     (image, error, cacheType) -> Void in 
     image = image.blurredImageWithRadius(30, iterations: 2, tintColor: UIColor.clearColor()) 
    } 
) 

的XCode甚至不认识的方法当我Cmd +点击它:“找不到符号”。

我怀疑它与块有什么关系,因为我可以调用同一类的其他方法,这几乎是相同的,但没有完成块。工作示例:

self.lastLookImageView.setImageWithURL(NSURL(string: self.lastLook!.image), placeholderImage: nil, options: SDWebImageRefreshCached) 

为背景的缘故:我用我混的OBJ-C和斯威夫特的项目称为SDWebImage(https://github.com/rs/SDWebImage)的组件。类已经导入我的桥接,Header.h

+1

'forState'参数在哪里,为什么有一个'完成的'参数卷到最后? – Abizern 2015-02-10 18:35:52

+0

完成处理程序存在,它在H文件上(https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImageView%2BWebCache.h#L129) – FRAGA 2015-02-11 11:12:16

+0

我编辑了问题以包含签名I正在谈论。对不起 – FRAGA 2015-02-11 11:14:00

回答

1

雨燕方法签名应该是:

func setImageWithURL(url: NSURL!, forState state: UIControlState, 
      placeholderImage placeholder: UIImage! options: SDWebImageOptions) 

所以你需要调用它:

self.lastLookImageView.setImageWithURL(url, forState: .Normal, 
      placeholderImage: nil, options: SDWebImageRefreshCached) 

有没有完成这种方法的处理程序,所以不要说了。

+0

实际上有一个完成处理程序的方法:https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImageView%2BWebCache.h#L129 – FRAGA 2015-02-11 11:11:49