简体   繁体   中英

Customized protocol's method is not calling in iphone sdk

I am having RouteSelectController from which I am navigating to RouteInfoController.

-(void)GoToRouteInfo
{
    RouteInfoController *controller = [[RouteInfoController alloc] initWithNibName:@"RouteInfoController" bundle:nil];

controller.delegate = self;
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}

In RouteInfoController.h I am creating my customized protocol like

#import <UIKit/UIKit.h>
@protocol RouteInfoDelegate;
@interface RouteInfoController : UIViewController<UITableViewDelegate, UITableViewDataSource, WptInfoDelegate>
{

    id<RouteInfoDelegate> delegate;
}
@property (nonatomic, assign) id delegate
@end

@protocol RouteInfoDelegate

- (void) deleteWptFromRouteAndAppWithUID;

@end

In RouteInfoController.m I called this delegate method like:

#import "MapViewController.h"
@class MapViewController;
@implementation RouteInfoController
@synthesize delegate;

-(void)callRouteDelegateMethod
{
  [self.delegate deleteWptFromRouteAndAppWithUID];
}

And the definition of this method is in MapViewController.m like:

#import "RouteInfoController.h"
@interface MapViewController () <UIScrollViewDelegate,RouteInfoDelegate>
{
    //.....................................
}

-(void) deleteWptFromRouteAndAppWithUID // The problem here is this delegate method is not called
{
    NSLog(@"\n Inside delete Way point...");

}

Edit: And when the control reaches to that delegate method in

-(void)callRouteDelegateMethod

in RouteInfoController I am get a crash message in my console like :

[RouteSelectController deleteWptFromRouteAndAppWithUID]: unrecognized selector sent to instance 0x6eb4eb0

Edit2:

In RootInfoController I am having a method on didselect of any cell of table view it calls this method

- (void) viewWptInfoControllerAtIndex: (int)index{

    WptInfoViewController *controller = [[WptInfoViewController alloc] initWithNibName:@"WptInfoViewController" bundle:nil];
    controller.asRootController = NO;
    controller.delegate = self;
    NSMutableDictionary *dict = [route.routeWaypoints objectAtIndex:index];
    NPLibWaypoint *libWpt = [NPLibWaypoint initWithDictionary:dict AndDelegateDS:delegateDS];
    controller.libWpt = libWpt;
       [libWpt release];
    controller.isFromRouteInfo = YES;
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];

}

Guy's cpls anyone suggest me How to resolve this and what's wrong I done.

Anyone's Help is deeply Appreciated.

Thanks All, Monish.

The error you're getting is pretty straightforward. It means that you're sending the message -deleteWptFromRouteAndAppWithUID to an instance of RouteSelectController , and that that class doesn't have that method. Some things to consider:

  • spelling: If you think that you've defined that method in that class, carefully check the spelling of the method name to make sure that the method you're calling exactly matches the name of the method that you've implemented. It's a pretty long name, and it'd be easy to get wrong. Remember that capitalization counts, as does the colon (or lack of colon).

  • receiver: Check that the object that's receiving the message really is the object that you intended. This message crops up sometimes when you've got a bad pointer, causing a case of mistaken identity.

It looks like it's the second point that's the problem in your case -- you've got an implementation of the method in MapViewController, but the error message indicates that that message is being sent to an instance of a different class (RouteSelectController). You may be changing RouteInfoController's delegate explicitly in your code somewhere, so look for that. But it may be the case that your RouteInfoController's delegate object is for some reason being deallocated, and a RouteSelectController happens to be created subsequently at that same address. When that happens, delegate points to the right place, but the wrong object is now there, and the error results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM