ios - 自定义View添加了协议,结果设置代理时出错了,根本不知道什么错好吗
迷茫
迷茫 2017-04-17 14:34:04
[iOS讨论组]

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

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)
伊谢尔伦

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号