簡體   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