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

发布于 2022-09-01 07:06:02 字数 1192 浏览 14 评论 0

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

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];

附图一张:
图片描述

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热血少△年 2022-09-08 07:06:02

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文