开发者

accessing function defined in another class using delegate method

开发者 https://www.devze.com 2023-04-01 20:00 出处:网络
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@\"didselectrowatindexatpath\");
- (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. 

I am getting error "Terminating app due to uncaught exception

'NSInvalidArgumentException', reason: '-[CortesAppDelegate showAddress]: unrecognized selector sent to instance 0x146ce0'"

at line

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

I used successfully following delegate method in code.

CortesAppDelegate *appDelegate = (CortesAppDelegate *)[[UIApplication sharedApplication] delegate];
      [appDelegate somefunction] ;

But when I tried sam开发者_如何学编程e thing for CortesViewController, application crashes. I am new to iOS. It might be possible that I am missing very simple point.

Can anyone tell me what is wrong with the code?

Thanks for help in advance


The problem is in following: method [[UIApplication sharedApplication] delegate]; returns object of class CortesAppDelegate. So you cannot call showAddress as it is defined in CortesViewController

0

精彩评论

暂无评论...
验证码 换一张
取 消