Iphone 使用委托方法访问另一个类中定义的函数

Iphone 使用委托方法访问另一个类中定义的函数,iphone,uiapplicationdelegate,Iphone,Uiapplicationdelegate,我收到错误“由于未捕获异常而终止应用程序 'NSInvalidArgumentException',原因:'-[CortesAppDelegate showAddress]:发送到实例0x146ce0的选择器无法识别' 排队 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didselectrowatindexatpath"); Plac

我收到错误“由于未捕获异常而终止应用程序

'NSInvalidArgumentException',原因:'-[CortesAppDelegate showAddress]:发送到实例0x146ce0的选择器无法识别'

排队

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"didselectrowatindexatpath");

Place *placeAtIndex = (Place *)[appDelegate.PlacesArray objectAtIndex:indexPath.row];

NSLog(@"required lat long is %f, %f ", placeAtIndex.PlaceLatitude, placeAtIndex.PlaceLongitude);



returnToMapDelegate = (CortesViewController *)[[UIApplication sharedApplication] delegate];



[returnToMapDelegate showAddress];  


}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  is Called in PlacesViewController.m and Function "showaddress" is defined in CortesViewController.h. 
我在代码中成功地使用了以下委托方法

returnToMapDelegate = (CortesViewController *)[[UIApplication sharedApplication] delegate];
但当我在CortesViewController上尝试同样的方法时,应用程序崩溃了。我是iOS新手。我可能遗漏了非常简单的一点

谁能告诉我代码有什么问题吗


提前感谢您的帮助

问题出在以下方面:方法
[[UIApplication sharedApplication]委托]
返回类的对象
CortesAppDelegate
。因此,您不能调用
showAddress
,因为它是在
CortesViewController

中定义的,在
CortesViewController
-(void)showAddress中实现您的方法
showAddress
{region.span.latitudeDelta=当前_因子;region.span.longitudeDelta=当前_因子;region.center.latitude=当前_纬度;region.center.longitude=当前_经度;[mymap setRegion:区域动画:TRUE];}感谢您的回复。您知道可以调用任何方法来访问CortesViewController.m中的函数吗?您应该使用类
CortesViewController
引用对象,然后将该消息发送给该对象谢谢朋友。我创建了CortesViewController的实例。并将消息传递给它,效果很好。Thnak太多了。
CortesAppDelegate *appDelegate = (CortesAppDelegate *)[[UIApplication sharedApplication] delegate];
      [appDelegate somefunction] ;