NSInvocation对象未获得分配的iphone sdk
我在做什么NSInvocation对象未获得分配的iphone sdk,iphone,nsinvocation,Iphone,Nsinvocation,我在做什么 NSString *_type_ = @"report"; NSNumber *_id_ = [NSNumber numberWithInt:report.reportId]; NSDictionary *paramObj = [NSDictionary dictionaryWithObjectsAndKeys: _id_, @"bla1", _type_, @"bla2
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];
但即使在处理了这一行之后,我的操作对象仍然是nil
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];
这里的选择器实际上是我正在编写的一个函数,类似于:
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];
-(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!!!");
}
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];
谁能指出我哪里出了错吗
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];
Thanx。选择器的名称是
initWithParserId:type:
,因此正确的行是
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 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(initParsersetId:type:) object:paramObj];
您的
@选择器
与您的方法签名不匹配,这就是它返回nil的原因。此外,不能使用便利构造函数传递多个参数。您必须创建一个NSInvocation
并使用initWithInvocation:
添加参数
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];
不,它仍然没有得到分配。:(我已经浏览了您提供的链接,但是在initWithTarget:selector:object:,我不能直接在nsdictionary对象中传递参数吗?我必须为多达10个不同的NSInvocationObject和Scott Stevenson的方法执行此过程[这太棒了],我想在我的例子中会引入冗余吗?而且在更改方法签名后它不会被分配。您不能在
NSDictionary
NSInvocation
中传递参数对象是可变的,因此您可以为10个不同的方法调用中的每一个编辑相同的对象。
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];