2010-06-11 21 views
0

我做NSInvocation的對象沒有得到分配的iPhone SDK的

 NSString *_type_ = @"report"; 
     NSNumber *_id_ = [NSNumber numberWithInt:report.reportId]; 

     NSDictionary *paramObj = [NSDictionary dictionaryWithObjectsAndKeys: 
           _id_, @"bla1", _type_, @"bla2",nil]; 

_operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(initParsersetId:) object:paramObj]; 

但我_operation對象是零甚至是處理此行之後。

這裏的選擇實際上是一個功能,我在寫這是這樣的:

-(void)initParsersetId:(NSInteger)_id_ type:(NSString *)_type_ 
{ 
NSString *urlStr = [NSString stringWithFormat:@"apimediadetails?id=624&type=report"]; 
NSString *finalURLstr = [urlStr stringByAppendingString:URL]; 
NSURL *url = [[NSURL alloc] initWithString:finalURLstr]; 

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; 

//Initialize the delegate. 
DetailedViewObject *parser = [[DetailedViewObject alloc] initDetailedViewObject]; 

//Set delegate 
[xmlParser setDelegate:parser]; 

//Start parsing the XML file. 
BOOL success = [xmlParser parse]; 

if(success) 
    NSLog(@"No Errors"); 
else 
    NSLog(@"Error Error Error!!!"); 

}

可有人請指出wheather我要去哪裏錯了。

Thanx提前。

回答

0

@selector不符合您的方法簽名,這就是爲什麼它返回零。此外,您不能使用便捷構造函數來傳遞多個參數。您必須創建一個NSInvocation並使用initWithInvocation:添加參數。

http://theocacao.com/document.page/264

+0

我已經通過你提供的鏈接了,但在initWithTarget:選擇:對象:,我不能傳遞參數的一個NSDictionary對象直接?我需要對多達10個不同的nsinvocationobjects和Scott Stevenson的方法(這真是太棒了)做這個過程,我會考慮在我的情況下引入冗餘,並且在更改方法簽名之後不會分配它 – neha 2010-06-11 13:30:06

+0

您可以'在NSDictionary中傳遞參數NSInvocation對象是可變的,所以你可以爲10個不同的方法調用編輯同一個對象。 – kubi 2010-06-11 15:14:44

0

您選擇的名稱爲initWithParserId:type:,所以正確的路線是

 

_operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(initParsersetId:type:) object:paramObj];
+0

沒有,它仍然沒有得到分配.. :( – neha 2010-06-11 13:15:37

相關問題