首页 > 自定义View添加了协议,结果设置代理时出错了,根本不知道什么错好吗

自定义View添加了协议,结果设置代理时出错了,根本不知道什么错好吗

首先是定义协议的时候根本没有任何提示,这个时候我就知道这个协议不回这么好实现了,其次就是各种写的时候没有自动补全提示,妈的,写下来已经很费劲了,结果,在设置代理的时候完全不能设置呀。自认为定义的没有问题,搞了好久觉得还是没问题呀。
代码如下:
定义协议:

1. LJmapView.h:
2. #import <UIKit/UIKit.h>
3. #import <Foundation/Foundation.h>
4. @protocol MapViewPointsDataSourceDelegate
5. - (NSArray *)getPoints;
6. @end
7. @interface LJmapView : UIView
8. @property (assign, nonatomic)id < MapViewPointsDataSourceDelegate > delegate;
9. - (void) setDelegate:(id)delegate;
10.@end

设置代理:

1. #import<UIKit/UIKit.h>
2. #import"LJmapView.h"
3. @interface LJViewController : UIViewController
4. @end"

实现部分:
_实现代理方法_

- (NSArray *)getPoints
{
return self.points;
}

设置代理:

UIView *linesView = [[LJmapView alloc]initWithFrame:self.view.bounds];
linesView.backgroundColor = [UIColor clearColor];
linesView.delegate = self;
[self.view addSubview:linesView];

附图一张:


改这几个个地方试试
1.@property (weak, nonatomic)id < MapViewPointsDataSourceDelegate > delegate;
2.@interface LJViewController : UIViewController <MapViewPointsDataSourceDelegate>
3.LJmapView *linesView = [[LJmapView alloc]initWithFrame:self.view.bounds];

【热门文章】
【热门文章】