我有一个符合MKAnnotation协议的自定义类.此类的一个实例由一个viewController和一个名为MKMapView的对象控制_mapView.我已将viewController设置为_mapView的委托.在我自己声明的自定义类接口中:
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
Run Code Online (Sandbox Code Playgroud)
因为它符合MKAnnotation协议的要求.我也在@synthesize同一个类的实现中.但是当我从viewController发送以下消息时:
[_mapView addAnnotation:myCustomClass];
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
<NSInvalidArgumentException> -[myCustomClass setCoordinate:]: unrecognized selector sent to instance 0x1479e0
Run Code Online (Sandbox Code Playgroud)
如果我进入我的自定义类的实现文件并定义
- (void) setCoordinate:(CLLocationCoordinate2D)newCoordinate
{
coordinate = newCoordinate;
}
Run Code Online (Sandbox Code Playgroud)
然后注释成功添加到地图中.
不@synthesize coordinate;应该照顾的setCoordinate:方法?奇怪的是,我既有@synthesize坐标也有写(void) setCoordinate:方法.
我错过了什么?
I\xe2\x80\x99m 尝试将五个新列表项添加到无序列表的末尾#myList。我的方法是执行以下操作:
const $newItem = $("<li>New Item</li>");\nconst $ul = $("#myList");\n\nfor(let i = 0; i < 5; ++i){\n $newItem.appendTo($ul);\n}\nRun Code Online (Sandbox Code Playgroud)\n然而,这不起作用,因为它只将一个列表项插入列表中,而不是五个。
\n在 R. Murphy\xe2\x80\x99s jQuery Fundamentals (在jQuery 基础知识部分的操作练习中)中,作者提供的解决方案与我的非常接近,唯一的区别是她没有\xe2\x80\x99t 存储变量中的新列表项,而是使用 HTML 字符串:
\nconst $ul = $("#myList");\n\nfor(let i = 0; i < 5; ++i){\n $("<li>List item " + i + "</li>").appendTo($ul);\n}\nRun Code Online (Sandbox Code Playgroud)\n看来我的方法也应该有效,所以我\xe2\x80\x99m努力理解为什么它不起作用\xe2\x80\x99t。为什么是这样?
\n我是Objective-C的新手,我的C/C++技能非常生疏.有什么更好的时间来学习iOS开发(!)
我正在尝试使用iOS中的CLGeocoder类来反转地理位置.我可以在块/回调中成功获取我感兴趣的数据(街道地址),但是当我尝试使用该数据填充我的变量(块外)时,数据不存在.就好像在MapView对象调用它之前块中的对象消失了.我正在使用__block,据我所知,应该允许变量在块外持久化,但似乎没有.
这是有问题的代码:
- (void) foundLocation:(CLLocation *)loc
{
CLLocationCoordinate2D coord = [loc coordinate];
// Get our city and state from a reversegeocode lookup and put them in the subtitle field (nowString).
// reversegeocode puts that information in a CLPlacemark object
// First, create the CLGeocoder object that will get us the info
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
// Next create a CLPlacemark object that we can store what reverseGeocodeLocation will give us containing the location data
__block CLPlacemark *placemark = …Run Code Online (Sandbox Code Playgroud)