h文件中符合客观的c协议

h文件中符合客观的c协议

本文介绍了如何在Swift的现有.h文件中符合客观的c协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Swift中重新创建一个Ray Wenderlich教程,但使用Swift和Objective C。主要部分(即视图控制器和模型)在Swift中完成,并使用现有的.h和.m类的桥接头。



我无法让我的快速浏览控制器符合对象委托。



在我的.h文件中我有:

  @class RWTRateView; 

@protocol RWTRateViewDelegate
- (void)rateView:(RWTRateView *)rateView ratingDidChange:(float)rating;
@end
@interface RWTRateView:UIView
...
@property(assign)id< RWTRateViewDelegate>代表;

@end

在我的快速文件中我有:

 class DetailViewController:UIViewController,UITextFieldDelegate,RWTRateViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

@IBOutlet var rateView:RWTRateView
...
func configureView(){
//更新详细信息的用户界面。
如果让细节:RWTScaryBugDoc = self.detailItem为? RWTScaryBugDoc {
如果let rv = self.rateView {
rv.notSelectedImage = UIImage(命名为shockedface2_empty.png)
rv.halfSelectedImage = UIImage(命名为shockedface2_half.png)
rv.fullSelectedImage = UIImage(命名为shockedface2_full.png)
rv.editable = true
rv.maxRating = 5
rv.delegate = self as RWTRateViewDelegate
rv.rating = detail.data.rating!
self.titleField.text = detail.data.title
self.imageView.image = detail.fullImage
}
}
}
...

func rateView(rateView:RWTRateView !, ratingDidChange rating:Float!) - > Void {

if let detail = self.detailItem as? RWTScaryBugDoc {
detail.data.rating = rating
}
}

...
}

由于某种原因,我收到一条错误消息,指出Type DetailContController不符合协议RWTRateViewDelegate,我不太确定为什么。



完整的代码位于。



感谢任何反馈,因为我花了最近3天在线寻找答案,但找不到

解决方案

你有:

  func rateView(rateView:RWTRateView !, ratingDidChange rating:Float!) - > Void {

我的Xcode 6(beta 2)自动填充此行为

  func rateView(rateView:RWTRateView !, ratingDidChange rating: CFloat){

请注意,第二个参数的类型是 CFloat ,而不是 Float!。 / p>

I am trying to recreate a Ray Wenderlich tutorial in Swift, but using both Swift and Objective C. The main part (i.e. view controllers and models) is done in Swift and using a bridging header for existing .h and .m classes.

I am having trouble trying to get my swift view controller to conform to a obj-c delegate.

In my .h file I have:

@class RWTRateView;

@protocol RWTRateViewDelegate
- (void)rateView:(RWTRateView *)rateView ratingDidChange:(float)rating;
@end
@interface RWTRateView : UIView
...
@property (assign) id <RWTRateViewDelegate> delegate;

@end

In my swift file I have:

class DetailViewController: UIViewController, UITextFieldDelegate, RWTRateViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var rateView : RWTRateView
...
    func configureView() {
            // Update the user interface for the detail item.
            if let detail:RWTScaryBugDoc = self.detailItem as? RWTScaryBugDoc {
                if let rv = self.rateView {
                    rv.notSelectedImage = UIImage(named: "shockedface2_empty.png")
                    rv.halfSelectedImage = UIImage(named: "shockedface2_half.png")
                    rv.fullSelectedImage = UIImage(named: "shockedface2_full.png")
                    rv.editable = true
                    rv.maxRating = 5
                    rv.delegate = self as RWTRateViewDelegate
                    rv.rating = detail.data.rating!
                    self.titleField.text = detail.data.title
                    self.imageView.image = detail.fullImage
                }
            }
        }
    ...

    func rateView(rateView:RWTRateView!, ratingDidChange rating:Float!) ->Void {

        if let detail = self.detailItem as? RWTScaryBugDoc {
            detail.data.rating = rating
        }
    }

...
}

For some reason, I'm getting an error message saying that Type 'DetailViewController" does not conform to protocol 'RWTRateViewDelegate' and I'm not quite sure why.

The full code is at https://github.com/dwmchan/ScaryBugsSwift.

Would appreciate any feedback on this because I've spent the last 3 days looking for answers online but couldn't find anything on this.

解决方案

You have:

func rateView(rateView:RWTRateView!, ratingDidChange rating:Float!) ->Void {

My Xcode 6 (beta 2) autocompletes this line as

func rateView(rateView: RWTRateView!, ratingDidChange rating: CFloat) {

Note that second parameter's type is CFloat, not Float!.

这篇关于如何在Swift的现有.h文件中符合客观的c协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 06:46