tags:

views:

107

answers:

3

I am new to objective C, So maybe there is some basic thing that I am missing about selectors. I would like to understand the basic concept behind this error as I have not found an general error reference.

I am getting this error when using:

[CloseButton addTarget:PageContents action:@selector(CloseButtonPressed) forControlEvents:UIControlEventTouchUpInside];

and then later:

- (void)CloseButtonPressed:(id)sender{
   UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Comment" message: @"hello" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
   [someError show];
   [someError release];
}
A: 

As CloseButtonPressed takes parameter you should create selector using: @selector(CloseButtonPressed:)

Vladimir
Thanks Guys, That did the trick.
eshalev
+3  A: 

A couple suggestions that will help your code follow writing conventions used by all Objective C applications, and make your code more easily readable to others:

  1. Object instances should be lower case, i.e. closeButton and not CloseButton, and pageContents, not PageContents
  2. Method names should be lower case, i.e. -closeButtonPressed: and not -CloseButtonPressed:

To answer your question, you need to fix the action you are adding:

[CloseButton addTarget:PageContents action:@selector(CloseButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

That colon character (:) makes sure the sender gets through to -CloseButtonPressed:

Alex Reynolds
A: 

Thanks Guys, That did the trick

eshalev
Just a note: Stackoverflow doesn't use the forum format i.e. a thread of post. Instead, it has a question and one or more answers. Each answer has its own comment thread. When a answer solves you problem you should hit the check mark next to it to indicate to the system and readers which answer solved your problem. To say thank, create a comment under than particular answer. That way, people researching a problem don't have to scroll through all the answers to find the right one.
TechZen