0

I'm creating programmatically a UIButton with an Image.

UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];
[bericht setBackgroundImage:[UIImage imageNamed:@"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];

- (void) imageClicked:(UIButton *) sender {
   NSLog(@"test message");
}

When I click on this button I got the following error code:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[__NSSetM goToFirstTrailer:]: unrecognized selector sent to instance 0x7fdaf1e73fe0'

Does anyone know a solution?

fsulser
  • 853
  • 2
  • 10
  • 34
  • where is goToFirstTrailer method being used? – Mrunal Dec 12 '14 at 11:24
  • Where is located this code. It looks like self = NSMutableSet – David Ansermot Dec 12 '14 at 11:26
  • I assume, you execute goToFirstTrailer method of NSSet collection which doesn't have such method – Injectios Dec 12 '14 at 11:26
  • Selector method spelling is different than its method. Replace `@selector(imageCLicked:)` with `@selector(imageClicked:)`. Do you get any warnings at that line? – Kampai Dec 12 '14 at 11:35
  • We need I bit more code, in order to know height. I think, In your didSelectRowAtIndexPath: methods you call goToFirstTrailler: (but only when the film has been selected. Probably your mistake is the cellForRow methods doesn't know the cell dimensions, and you are thinking that you are creating you button in a place but it's out the screen, and didSelectRowAtIndexPath: is call when you don't want that. (But I say this like play a magic). – Onik IV Dec 12 '14 at 11:36
  • Its nothing more than a Method name capitalisation issue. Just copy your Method name & paste it to selector. – cyberlobe Dec 12 '14 at 11:48
  • Stupid spelling misstake sorry. But changig to the same doesn't helped. Got the same error – fsulser Dec 12 '14 at 12:00
  • I think hight is not the problem because the image is in the tablerow. The goToFirstTrailler was just e method trying to debug. In the didSelectRowAtIndexPath: method I'm not doing anything. – fsulser Dec 12 '14 at 12:10

1 Answers1

1

Change your selector method to imageClicked.

UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];

[bericht setBackgroundImage:[UIImage imageNamed:@"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];

- (void) imageClicked:(UIButton *) sender {
   NSLog(@"iaksdkjas");
}
Kampai
  • 22,848
  • 21
  • 95
  • 95
Dheeraj Singh
  • 5,143
  • 25
  • 33