2012-03-10 35 views
0

我有RouteSelectController我從中導航到RouteInfoController。自定義協議的方法是不是在iPhone調用sdk

-(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

EDIT2:

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

} 

蓋伊的CPL的人建議我如何解決這一點,什麼是錯的我做了。

任何人的幫助深受讚賞。

謝謝大家, Monish。

+0

「RouteSelectController」來自哪裏?我以爲你想使用MapViewController作爲你的委託..也許你設置委託錯了? – 2012-03-10 09:28:46

+0

Thats wt我很困惑y RouteSelectorController進來之間。我做了同樣的事,因爲我發佈了這個問題的代碼。 – 2012-03-10 09:41:46

+0

請向我們展示您設置委託對象的代碼 – 2012-03-10 10:20:46

回答

1

你得到的錯誤是非常簡單的。這意味着您要將消息-deleteWptFromRouteAndAppWithUID發送到RouteSelectController的實例,並且該類沒有該方法。有些事情要考慮:

  • 拼寫:如果你認爲你已經定義在類中的方法,仔細檢查方法名稱的拼寫,以確保你調用的方法完全一致您實施的方法的名稱。這是一個很長的名字,很容易出錯。請記住,大寫字母和冒號(或冒號)不一樣。

  • receiver:檢查接收消息的對象是否真的是您想要的對象。這個消息有時候會在你指針錯誤時突然出現,導致一個錯誤的身份。

看起來它是在你的情況下,問題的第二點 - 你有在的MapViewController該方法的實現,但該錯誤消息指出該消息被髮送到的一個實例不同的類(RouteSelectController)。您可能會在代碼中顯式更改RouteInfoController的委託,因此請仔細查看。但可能出現這種情況,您的RouteInfoController的委託對象由於某種原因被解除分配,並且隨後在同一地址創建了RouteSelectController。當發生這種情況時,delegate指向正確的位置,但錯誤的對象現在在那裏,並且出現錯誤。