繁体   English   中英

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

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

我有从中导航到RouteInfoController的RouteSelectController。

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

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

在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

在RouteInfoController.m中,我将此委托方法称为:

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

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

该方法的定义在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...");

}

编辑:当控件到达该委托方法时

-(无效)callRouteDelegateMethod

在RouteInfoController中,我在控制台中收到崩溃消息,例如:

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

编辑2:

在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];

}

盖伊的cpls有人建议我如何解决此问题以及我做错了什么。

大家的帮助深表感谢。

谢谢大家,Monish。

您得到的错误非常简单。 这意味着你要发送的消息-deleteWptFromRouteAndAppWithUID到的实例RouteSelectController ,而且该类没有这种方法。 要考虑的一些事情:

  • 拼写:如果您认为已在该类中定义了该方法,请仔细检查该方法名称的拼写,以确保所调用的方法与您实现的方法的名称完全匹配。 这是一个很长的名字,容易出错。 请记住,大写和冒号(或冒号的缺乏)一样重要。

  • 接收者:检查接收消息的对象确实是您想要的对象。 当您的指针指向错误时,有时会出现此消息,从而导致身份错误。

看来这是您遇到的问题的第二点-您已经在MapViewController中实现了该方法的实现,但错误消息表明该消息正在发送到其他类的实例(RouteSelectController)。 您可能在代码中的某处显式更改了RouteInfoController的委托,因此请查找。 但是,可能是由于某种原因而释放了RouteInfoController的委托对象,并且随后在该相同地址上创建了一个RouteSelectController的情况。 发生这种情况时, delegate指向正确的位置,但是现在存在错误的对象,并产生错误。

暂无
暂无

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

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