Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何执行对象';内部功能_Iphone_Objective C_Oop_Class_Ios4 - Fatal编程技术网

Iphone 如何执行对象';内部功能

Iphone 如何执行对象';内部功能,iphone,objective-c,oop,class,ios4,Iphone,Objective C,Oop,Class,Ios4,因此,我对面向对象编程非常陌生,我正在尝试在xcode中执行以下操作-我有一个MyMap.m视图控制器,在其中显示您的位置,现在想添加天气。为此,我想将坐标发送给geocoder类,该类将首先返回zipcode。我决定用类来加热它,所以创建了一个将返回zipcode的类 地图控制器中的代码为: 其中,getzip是GetZipcode类的实例: @interface MyMap : UIViewController <MKMapViewDelegate, MyLocationContr

因此,我对面向对象编程非常陌生,我正在尝试在xcode中执行以下操作-我有一个MyMap.m视图控制器,在其中显示您的位置,现在想添加天气。为此,我想将坐标发送给geocoder类,该类将首先返回zipcode。我决定用类来加热它,所以创建了一个将返回zipcode的类

地图控制器中的代码为:

其中,getzip是GetZipcode类的实例:

@interface MyMap : UIViewController <MKMapViewDelegate, MyLocationControllerDelegate> {

              GetZipcode *getzip;
 //and more stuff
 }
哪个reverseGeocodeCurrentLocation是GetZipcode类中的函数:

@interface MyMap : UIViewController <MKMapViewDelegate, MyLocationControllerDelegate> {

              GetZipcode *getzip;
 //and more stuff
 }
h

该类的.m为:

- (void)reverseGeocodeCurrentLocation
{
self.reverseGeocoder = [[[MKReverseGeocoder alloc] init] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
PlacemarkViewController *placemarkViewController = [[PlacemarkViewController alloc] initWithNibName:@"PlacemarkViewController" bundle:nil];
placemarkViewController.placemark = placemark;
myPlacemark = placemark;
NSLog(@"Placemark is: %@", placemark.postalCode);
 }

希望不是TMI,但我真的非常感谢您的帮助。谢谢

您没有给MKReverseGeocoder一个坐标来反转地理代码

指定的初始值设定项是-[MKReverseGeocoder initWithCoordinate:],通过它可以提供坐标

希望有帮助

(当然,还要检查您是否创建并初始化了GetZipcode实例,并且在尝试使用它时getzip不是nil。)

编辑:

您创建了一个名为getzip的实例变量(ivar)。但是您没有发布任何创建GetZipcode实例并将该地址放入指针getzip的代码。在某个地方,你应该有这样的东西:

getzip = [[GetZipcode alloc] someAppropriateInit];
第二次编辑

还有几件事需要考虑。(1) 在此处尝试执行以下操作时,实际上无法立即读取placemark属性:

zip = getzip.myPlacemark;
这将需要一段时间的反向地理编码器走出去的网络,做它的工作,并找出了地标。因此,在获得委托回调之前,您不会有一个placemark:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
(2) 您还应该实现此回调,以便查看查找placemark时是否出现问题:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error

(3) 您确定要将有效坐标传递给反向地理编码器吗?您可能需要将其记录下来以确保绝对可靠。

我没有看到任何您实例化getZip的代码。此外,您不能期望它在启动reverseGeocoder后直接具有一个placemark;这不是这种服务的工作方式——你可能已经猜到了,因为你实现了一个方法,当反向地理编码器发现某些东西时,就会调用该方法。在反向地理编码器返回一个placemark之前,您向您的对象询问placemark(反向地理编码器与您的应用程序一起运行;应用程序不会等待它返回)。这不是实例化getZip的方法吗?(见上图):GetZipcode*getzip;我在使用getzip的对象的头文件上做了什么?看起来我的回调(reverseGeocoder:didFindPlacemark)没有被调用-有什么想法吗?一些基本概念:创建一个变量(在本例中,是一个实例变量或短iVar)只是为一个带有名称标签的对象预留一个位置。对象是类的实例。所以你已经声明了一个空座位,但是你没有创建一个坐在那里的对象。您通常通过调用
[SomeClass alloc]init…]
方法来创建对象。有些类提供了方便的方法,可以将初始化的对象返回给您,比如
[UIColor blackColor]
,但在幕后,它们基本上也执行alloc init操作。现在就初始化它,但这并不能解决问题。我还看到,你们都说要实例化getZip,但我确实这么做了(在上面的第二个代码框中)。我做错了吗?不,第二个代码块显示了为名为getzip的实例变量保留的空间。但是您没有在发布的代码中创建任何GetZipcode对象。你能更新代码以确保我们看到的是相同的东西吗?在上面添加了这个实例。现在它“进入”对象,但不返回zipcode。我猜@fzwo就在这里-但我不确定如何正确运行这些方法。好的,非常感谢,这非常有帮助!知道我正在进入这个对象和didFindPlacemark,但是如何将placemark返回到父对象?(其中我实例化了GetZipcode对象)。再次感谢!!
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error