使用swift将tableview的委托设置为另一个类

时间:2014-12-04 07:35:18

标签: uitableview swift delegates

我想将tableview的委托设置为UITableViewController中的另一个自定义类, 对于objectC来说没关系,但是使用Swift会出错,详细信息如下图所示。 旧的objectC代码在这里:https://github.com/ninjinkun/NJKScrollFullScreen

1,在ObjectC中确定:

#import "ViewController.h"
#import "UIViewController+NJKFullScreenSupport.h"

@interface ViewController ()
@property (nonatomic) NSArray *data;
@property (nonatomic) NJKScrollFullScreen *scrollProxy;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    _scrollProxy = [[NJKScrollFullScreen alloc] initWithForwardTarget:self]; // UIScrollViewDelegate and UITableViewDelegate methods proxy to ViewController

    self.tableView.delegate = (id)_scrollProxy; // cast for surpress incompatible warnings

    _scrollProxy.delegate = self;
}
....
@end    

2,Swift中的错误,我想也许是它的类型转换问题: 错误:see error

class GLBaseTableViewController : UITableViewController,NJKScrollFullscreenDelegate{
var dataSource = []
var scrollProxy:NJKScrollFullScreen!
override func viewDidLoad() {
    super.viewDidLoad()

    scrollProxy = NJKScrollFullScreen(forwardTarget: self)
    self.tableView.delegate = scrollProxy
    scrollProxy.delegate = self
}

3,委托ob:

@protocol NJKScrollFullscreenDelegate;

@interface NJKScrollFullScreen : NSObject<UIScrollViewDelegate>

@property (nonatomic, weak) id<NJKScrollFullscreenDelegate> delegate;

0 个答案:

没有答案