views:

45

answers:

2

Hi all,

I'm using NSInvocation as follows:

In my init, I'm writing this in my viewDidLoad:

SEL mySelector;
mySelector = @selector(initParsersetId:type:);

NSMethodSignature * sig = nil;
sig = [[self class] instanceMethodSignatureForSelector:mySelector];

myInvocation = nil;
myInvocation = [NSInvocation invocationWithMethodSignature:sig];
[myInvocation setTarget:self];
[myInvocation setSelector:mySelector];

And I'm calling it like this:

Idea *tempIdea = [[Idea alloc]init];
tempIdea = [genericArray objectAtIndex:indexPath.row];
idea.ideaId = tempIdea.ideaId;
[tempIdea release];

NSNumber *_id_ = [NSNumber numberWithInt:idea.ideaId];
[myInvocation setArgument:_id_ atIndex:2];  //CRASHING AT THIS LINE

My application is crashing at the indicated line. Can anybody please help me?

A: 

I've found the answer but I'm not convinced how. Actually, initially I was writing all the initialisation code in viewDidLoad and simply reusing the NSInvocation object by passing it the different argument since NSInvocation is a mutable object. It didn't work. Then I wrote a method with all the initialisation code inside it and called that method every time I used the NSInvocation object and it worked...

neha
A: 

It is not very clear from your codes; however, I see something suspicious. Hopefully, it may provide your some helpful hints.

First, I don't see you retain the instance (auto released from [NSInvocation...). Since the instance from [NSInvocation...] is auto-released, your class level variable myInvocation would not retain it after viewDidLoad event.

Second thing in your codes is that the selector is a kind of customized constructor, beginning with init..... I am not sure if you can invoke the event within the same instance. Another point is that if your init... method to be invoked returns self? It should be.

You may output some messages in your selector event by using NSLog function. All the messages by NSLog will be in your XCode's output console.

David.Chu.ca
Thanx David.. It helped..
neha