J'essaie d'ajouter un bouton de manière programmatique de telle manière qu'en appuyant sur celui-ci, un certain objet soit passé. Je continue d'obtenir l'exception "sélecteur non reconnu envoyé". Pouvez-vous suggérer ce qui est erroné avec le code:UIButton avec NSInvocation
// allocate the details button's action
SEL selector = @selector(showPropertyDetails:forProperty:);
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
//The invocation object must retain its arguments
[property retain];
//Set the arguments
[invocation setTarget:self];
[invocation setArgument:&property atIndex:3];
[(UIButton*)[myView viewWithTag:15] addTarget:self action:@selector(selector) forControlEvents:UIControlEventTouchDown];
et plus bas, la méthode dans la même classe ressemble à:
-(void) showPropertyDetails:(id)something forProperty:(Property *)property {
int i=0;
}
Donc vous voulez dire le seul moyen d'envoyer plusieurs arguments sur un bouton clic pour utiliser l'objet de collection (dictionnaire, tableau etc) car ils prendront toujours un seul argument? – Amarsh
@Amarsh: Je veux dire que vous ne pouvez pas utiliser incovations et al ici et à la place devez stocker l'information et la relation au bouton ailleurs. –
@George: Ouais merci. Votre commentaire m'a aidé à résoudre mon problème. Thans pour ça. – Amarsh