简体   繁体   English

自定义协议的方法未在iPhone SDK中调用

[英]Customized protocol's method is not calling in iphone sdk

I am having RouteSelectController from which I am navigating to RouteInfoController. 我有从中导航到RouteInfoController的RouteSelectController。

-(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 在RouteInfoController.h中,我正在创建自己的自定义协议,例如

#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: 在RouteInfoController.m中,我将此委托方法称为:

#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: 该方法的定义在MapViewController.m中,如下所示:

#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 -(无效)callRouteDelegateMethod

in RouteInfoController I am get a crash message in my console like : 在RouteInfoController中,我在控制台中收到崩溃消息,例如:

[RouteSelectController deleteWptFromRouteAndAppWithUID]: unrecognized selector sent to instance 0x6eb4eb0 [RouteSelectController deleteWptFromRouteAndAppWithUID]:无法识别的选择器已发送到实例0x6eb4eb0

Edit2: 编辑2:

In RootInfoController I am having a method on didselect of any cell of table view it calls this method 在RootInfoController中,我在表视图的任何单元格的didselect上都有一个方法,它调用此方法

- (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. 盖伊的cpls有人建议我如何解决此问题以及我做错了什么。

Anyone's Help is deeply Appreciated. 大家的帮助深表感谢。

Thanks All, Monish. 谢谢大家,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. 这意味着你要发送的消息-deleteWptFromRouteAndAppWithUID到的实例RouteSelectController ,而且该类没有这种方法。 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). 看来这是您遇到的问题的第二点-您已经在MapViewController中实现了该方法的实现,但错误消息表明该消息正在发送到其他类的实例(RouteSelectController)。 You may be changing RouteInfoController's delegate explicitly in your code somewhere, so look for that. 您可能在代码中的某处显式更改了RouteInfoController的委托,因此请查找。 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. 但是,可能是由于某种原因而释放了RouteInfoController的委托对象,并且随后在该相同地址上创建了一个RouteSelectController的情况。 When that happens, delegate points to the right place, but the wrong object is now there, and the error results. 发生这种情况时, delegate指向正确的位置,但是现在存在错误的对象,并产生错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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